Calculate and return x and exp such that value =x*2exp and .5 <= |x| < 1.0
x has same sign as value.
value | returns | exp |
---|---|---|
±0.0 | ±0.0 | 0 |
+∞ | +∞ | unchenged |
-∞ | -∞ | unchenged |
±NaN | ±NaN | unchenged |
import mir.math.common: pow, approxEqual; alias isNaN = x => x != x; int exp; real mantissa = frexp(123.456L, exp); assert(approxEqual(mantissa * pow(2.0L, cast(real) exp), 123.456L)); // special cases, zero assert(frexp(-0.0, exp) == -0.0 && exp == 0); assert(frexp(0.0, exp) == 0.0 && exp == 0); // special cases, NaNs and INFs exp = 1234; // random number assert(isNaN(frexp(-real.nan, exp)) && exp == 1234); assert(isNaN(frexp(real.nan, exp)) && exp == 1234); assert(frexp(-real.infinity, exp) == -real.infinity && exp == 1234); assert(frexp(real.infinity, exp) == real.infinity && exp == 1234);
Separate floating point value into significand and exponent.