View source code
Display the source code in std/math.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.feqrel
To what precision is x equal to y?
int feqrel(X)
(
const X x,
const X y
) pure nothrow @nogc @trusted
if (isFloatingPoint!X);
Returns
the number of mantissa bits which are equal in x and y. eg, 0x1.F8p+60 and 0x1.F1p+60 are equal to 5 bits of precision.
x | y | feqrel(x, y) |
---|---|---|
x | x | real.mant_dig |
x | >= 2*x | 0 |
x | <= x/2 | 0 |
NAN | any | 0 |
any | NAN | 0 |
Example
writeln(feqrel(2.0, 2.0)); // 53
writeln(feqrel(2.0f, 2.0f)); // 24
writeln(feqrel(2.0, double .nan)); // 0
// Test that numbers are within n digits of each
// other by testing if feqrel > n * log2(10)
// five digits
assert(feqrel(2.0, 2.00001) > 16);
// ten digits
assert(feqrel(2.0, 2.00000000001) > 33);
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.