The OpenD Programming Language

frexp

Separate floating point value into significand and exponent.

@trusted pure nothrow @nogc
T
frexp
(
T
)
(
const T value
,
ref int exp
)
if (
isFloatingPoint!T
)

Return Value

Type: T

Calculate and return x and exp such that value =x*2exp and .5 <= |x| < 1.0

x has same sign as value.

Special Values
valuereturnsexp
±0.0±0.00
+∞+∞unchenged
-∞-∞unchenged
±NaN±NaNunchenged

Examples

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);

Meta