For the complete Mojo documentation index, see llms.txt. Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).
FastMathFlag
struct FastMathFlag
Flags for controlling fast-math optimizations in floating-point operations.
FastMathFlag provides compile-time controls for various floating-point math optimization modes that trade strict IEEE 754 compliance for performance.
Available flags:
none: No fast-math optimizations.nnan: Assume operands and results are not NaN.ninf: Assume operands and results are not +/- infinity.nsz: Treat the sign of a zero as insignificant.arcp: Allow reciprocal of values.contract: Allow floating-point contraction (e.g., fused multiply-add).afn: Allow algebraic function approximations.reassoc: Allow reassociation of floating-point operations.fast: Enable all fast-math optimizations.
Examples:
from std.simd import FastMathFlag
var value = Float32(2.0)
var multiplier = Float32(3.0)
var accumulator = Float32(1.0)
# Use contract flag for fused multiply-add
var result = value.fma[FastMathFlag.contract](multiplier, accumulator)
# Use fast flag for maximum optimization
var fast_result = value.fma[FastMathFlag.fast](multiplier, accumulator)
Implemented traits
AnyType,
Copyable,
Deinitable,
EnumLike,
Equatable,
ImplicitlyCopyable,
Movable,
RegisterPassable,
Writable
comptime members
afn
comptime afn = FastMathFlag(UInt8(6))
Allow approximate function implementations.
AFN
comptime AFN = FastMathFlag.afn
Deprecated: The former name of afn.
Deprecated: 'AFN' is deprecated, use 'afn' instead
arcp
comptime arcp = FastMathFlag(UInt8(4))
Allow reciprocal approximations.
ARCP
comptime ARCP = FastMathFlag.arcp
Deprecated: The former name of arcp.
Deprecated: 'ARCP' is deprecated, use 'arcp' instead
contract
comptime contract = FastMathFlag(UInt8(5))
Allow floating-point contraction.
CONTRACT
comptime CONTRACT = FastMathFlag.contract
Deprecated: The former name of contract.
Deprecated: 'CONTRACT' is deprecated, use 'contract' instead
fast
comptime fast = FastMathFlag(UInt8(8))
Enable all fast-math optimizations.
FAST
comptime FAST = FastMathFlag.fast
Deprecated: The former name of fast.
Deprecated: 'FAST' is deprecated, use 'fast' instead
ninf
comptime ninf = FastMathFlag(UInt8(2))
Assume no infinite values.
NINF
comptime NINF = FastMathFlag.ninf
Deprecated: The former name of ninf.
Deprecated: 'NINF' is deprecated, use 'ninf' instead
nnan
comptime nnan = FastMathFlag(UInt8(1))
Assume no NaN values.
NNAN
comptime NNAN = FastMathFlag.nnan
Deprecated: The former name of nnan.
Deprecated: 'NNAN' is deprecated, use 'nnan' instead
none
comptime none = FastMathFlag(UInt8(0))
No fast-math optimizations enabled.
NONE
comptime NONE = FastMathFlag.none
Deprecated: The former name of none.
Deprecated: 'NONE' is deprecated, use 'none' instead
nsz
comptime nsz = FastMathFlag(UInt8(3))
Treat the sign of zero as insignificant.
NSZ
comptime NSZ = FastMathFlag.nsz
Deprecated: The former name of nsz.
Deprecated: 'NSZ' is deprecated, use 'nsz' instead
reassoc
comptime reassoc = FastMathFlag(UInt8(7))
Allow reassociation of operations.
REASSOC
comptime REASSOC = FastMathFlag.reassoc
Deprecated: The former name of reassoc.
Deprecated: 'REASSOC' is deprecated, use 'reassoc' instead
Methods
__eq__
def __eq__(self, other: Self) -> Bool
Compares two FastMathFlag values for identity.
Args:
- other (
Self): The FastMathFlag to compare against.
Returns:
Bool: True if both flags have the same value, False otherwise.
write_to
def write_to(self, mut writer: T)
Writes a string representation of the FastMathFlag to the provided writer.
Args:
- writer (
T): The object to write to.
write_repr_to
def write_repr_to(self, mut writer: T)
Writes a repr string of the FastMathFlag to the provided writer.
Args:
- writer (
T): The object to write to.