From 0964947dee35e164e25976d5cc0bf22b70c20c34 Mon Sep 17 00:00:00 2001 From: Alfred Broderick Date: Wed, 10 Apr 2024 15:50:49 -0400 Subject: [PATCH] Update 04_Math-Functions.md Added examples --- Docs/03_Advanced/04_Math-Functions.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Docs/03_Advanced/04_Math-Functions.md b/Docs/03_Advanced/04_Math-Functions.md index 8a62113a2..e4e250789 100644 --- a/Docs/03_Advanced/04_Math-Functions.md +++ b/Docs/03_Advanced/04_Math-Functions.md @@ -14,12 +14,21 @@ unprecise) math functions. Unlike previous versions, the fast-math mode applies to all math instructions. Even to default math operations like `x / y`. +```C# +Context context = Context.Create(builder => builder.Math(MathMode.Fast)); +``` + ### Forced 32-bit Math Your kernels might rely on third-party functions that are not under your control. These functions typically depend on the default .Net `Math` class, and thus, work on 64-bit floating-point operations. You can force the use of 32-bit floating-point operations in all cases using the `Math(MathMode.Fast32BitOnly)` method of `Context.Builder`. -Caution: all doubles will be considered as floats to circumvent issues with third-party code. + +```c# +Context context = Context.Create(builder => builder.Math(MathMode.Fast32BitOnly)); +``` + +Caution: All doubles will be considered as floats to circumvent issues with third-party code. However, this also affects the address computations of array-view elements. Avoid the use of this flag unless you know exactly what you are doing.