Skip to main content

Mojo struct

FastMathFlag

@register_passable 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:

# 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, ImplicitlyCopyable, Movable, UnknownDestructibility

Aliases

__copyinit__is_trivial

alias __copyinit__is_trivial = True

__del__is_trivial

alias __del__is_trivial = True

__moveinit__is_trivial

alias __moveinit__is_trivial = True

AFN

alias AFN = FastMathFlag(6)

ARCP

alias ARCP = FastMathFlag(4)

CONTRACT

alias CONTRACT = FastMathFlag(5)

FAST

alias FAST = FastMathFlag(8)

NINF

alias NINF = FastMathFlag(2)

NNAN

alias NNAN = FastMathFlag(1)

NONE

alias NONE = FastMathFlag(0)

NSZ

alias NSZ = FastMathFlag(3)

REASSOC

alias REASSOC = FastMathFlag(7)

Methods

__is__

__is__(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.

Was this page helpful?