View source code
Display the source code in std/math/exponential.d from which this
page was generated on github.
Report a bug
If you spot a problem with this page, click here to create a
Bugzilla issue.
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.
Function std.math.exponential.frexp
Separate floating point value into significand and exponent.
T frexp(T)
(
const T value,
out 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 |
±NAN | ±NAN | int.min |
Example
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);
Authors
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw and David Nadlinger
License
Copyright © 1999-2022 by the D Language Foundation | Page generated by ddox.