std.math.IeeeFlags/ieeeFlags
- multiple declarations
Function ieeeFlags
Returns
snapshot of the current state of the floating-point status flags
Example
pragma(inline, false) static void blockopt(ref real x) {}
resetIeeeFlags();
real a = 3.5;
blockopt(a); // avoid constant propagation by the optimizer
a /= 0.0L;
writeln(a); // real.infinity
assert(ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
a *= 0.0L;
assert(isNaN(a));
assert(ieeeFlags .invalid);
}
Function ieeeFlags
Returns
snapshot of the current state of the floating-point status flags
Example
pragma(inline, false) static void blockopt(ref real x) {}
resetIeeeFlags();
real a = 3.5;
blockopt(a); // avoid constant propagation by the optimizer
a /= 0.0L;
writeln(a); // real.infinity
assert(ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
a *= 0.0L;
assert(isNaN(a));
assert(ieeeFlags .invalid);
}
Struct IeeeFlags
IEEE exception status flags ('sticky bits')
struct IeeeFlags
;
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 |
inexact [get]
|
bool | The result cannot be represented exactly, so rounding occurred. |
invalid [get]
|
bool | A machine NaN was generated. |
overflow [get]
|
bool | An infinity was generated by overflow |
underflow [get]
|
bool | A zero was generated by underflow |
Example
static void func() {
int a = 10 * 10;
}
pragma(inline, false) static void blockopt(ref real x) {}
real a = 3.5;
// Set all the flags to zero
resetIeeeFlags();
assert(!ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
// Perform a division by zero.
a /= 0.0L;
writeln(a); // real.infinity
assert(ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
// 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();
writeln(ieeeFlags); // f
Struct IeeeFlags
IEEE exception status flags ('sticky bits')
struct IeeeFlags
;
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 |
inexact [get]
|
bool | The result cannot be represented exactly, so rounding occurred. |
invalid [get]
|
bool | A machine NaN was generated. |
overflow [get]
|
bool | An infinity was generated by overflow |
underflow [get]
|
bool | A zero was generated by underflow |
Example
static void func() {
int a = 10 * 10;
}
pragma(inline, false) static void blockopt(ref real x) {}
real a = 3.5;
// Set all the flags to zero
resetIeeeFlags();
assert(!ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
// Perform a division by zero.
a /= 0.0L;
writeln(a); // real.infinity
assert(ieeeFlags .divByZero);
blockopt(a); // avoid constant propagation by the optimizer
// 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();
writeln(ieeeFlags); // f
Authors
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger