The OpenD Programming Language

feqrel

To what precision is x equal to y?

@trusted pure nothrow @nogc
int
feqrel
(
T
)
(
const T x
,
const T y
)
if (
isFloatingPoint!T
)

Return Value

Type: int

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.

Special Values
xyfeqrel(x, y)
xxreal.mant_dig
x>= 2*x0
x<= x/20
NaNany0
anyNaN0

Examples

assert(feqrel(2.0, 2.0) == 53);
assert(feqrel(2.0f, 2.0f) == 24);
assert(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);

Meta