@setFloatMode

@setFloatMode

@setFloatMode(mode: @import("builtin").FloatMode)

Sets the floating point mode of the current scope. Possible values are:

pub const FloatMode = enum {
    Strict,
    Optimized,
};
  • Strict (default) - Floating point operations follow strict IEEE compliance.
  • Optimized - Floating point operations may do all of the following:

    • Assume the arguments and result are not NaN. Optimizations are required to retain defined behavior over NaNs, but the value of the result is undefined.
    • Assume the arguments and result are not +/-Inf. Optimizations are required to retain defined behavior over +/-Inf, but the value of the result is undefined.
    • Treat the sign of a zero argument or result as insignificant.
    • Use the reciprocal of an argument rather than perform division.
    • Perform floating-point contraction (e.g. fusing a multiply followed by an addition into a fused multiply-and-add).
    • Perform algebraically equivalent transformations that may change results in floating point (e.g. reassociate).

This is equivalent to -ffast-math in GCC.

The floating point mode is inherited by child scopes, and can be overridden in any scope. You can set the floating point mode in a struct or module scope by using a comptime block.

See also:

  • Floating Point Operations