View source code Display the source code in std/math.d from which this page was generated on github. Improve this page Quickly fork, edit online, and submit a pull request for this page. Requires a signed-in GitHub account. This works well for small changes. If you'd like to make larger changes you may want to consider using local clone. Page wiki View or edit the community-maintained wiki page associated with this page.

std.math.ieee_flags - multiple declarations

Function ieeeFlags

Return a snapshot of the current state of the floating-point status flags.

Prototype

IeeeFlags ieeeFlags() @property;

Struct IeeeFlags

IEEE exception status flags ('sticky bits')

These flags indicate that an exceptional floating-point condition has occurred. They indicate that a NaN or an infinity has been generated, that a result is inexact, or that a signalling NaN has been encountered. If floating-point exceptions are enabled (unmasked), a hardware exception will be generated instead of setting these flags.

Properties

Name Type Description
divByZero [get] bool An infinity was generated by division by zero (example: x = 3/0.0; )
inexact [get] bool The result cannot be represented exactly, so rounding occurred.
invalid [get] bool A machine NaN was generated. (example: x = real.infinity * 0.0; )
overflow [get] bool An infinity was generated by overflow (example: x = real.max*2;)
underflow [get] bool A zero was generated by underflow (example: x = real.min*real.epsilon/2;)

Example

static void func() {
    int a = 10 * 10;
}

real a=3.5;
// Set all the flags to zero
resetIeeeFlags();
assert(!ieeeFlags.divByZero);
// Perform a division by zero.
a/=0.0L;
assert(a==real.infinity);
assert(ieeeFlags.divByZero);
// Create a NaN
a*=0.0L;
assert(ieeeFlags.invalid);
assert(isNaN(a));

// Check that calling func() has no effect on the
// status flags.
IeeeFlags f = ieeeFlags;
func();
assert(ieeeFlags == f);

Authors

Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw

License

Boost License 1.0.

Comments