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.

Function std.math.frexp

Separate floating point value into significand and exponent.

Prototype

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

Returns

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

Example

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

// check if values are equal to 19 decimal digits of precision
assert(equalsDigit(mantissa * pow(2.0L, cast(real)exp), 123.456L, 19));

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

Authors

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

License

Boost License 1.0.

Comments