frexp

Separate floating point value into significand and exponent.

@trusted pure nothrow @nogc
T
frexp
(
T
)
(
const T value
,
out int exp
)

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
+∞+∞int.max
-∞-∞int.min
±NaN±NaNint.min

Examples

import std.math.operations : isClose;

int exp;
real mantissa = frexp(123.456L, exp);

assert(isClose(mantissa * pow(2.0L, cast(real) exp), 123.456L));

assert(frexp(-real.nan, exp) && exp == int.min);
assert(frexp(real.nan, exp) && exp == int.min);
assert(frexp(-real.infinity, exp) == -real.infinity && exp == int.min);
assert(frexp(real.infinity, exp) == real.infinity && exp == int.max);
assert(frexp(-0.0, exp) == -0.0 && exp == 0);
assert(frexp(0.0, exp) == 0.0 && exp == 0);

Meta