std.math.approx_equal - multiple declarations
- Function approxEqual
- Function approxEqual
Function approxEqual
Returns .
approxEqual(lhs, rhs, 1e-2, 1e-5)
Prototype
bool approxEqual(T, U)( T lhs, U rhs );
Example
assert(approxEqual(1.0, 1.0099)); assert(!approxEqual(1.0, 1.011)); float[] arr1 = [ 1.0, 2.0, 3.0 ]; double[] arr2 = [ 1.001, 1.999, 3 ]; assert(approxEqual(arr1, arr2)); real num = real.infinity; assert(num == real.infinity); // Passes. assert(approxEqual(num, real.infinity)); // Fails. num = -real.infinity; assert(num == -real.infinity); // Passes. assert(approxEqual(num, -real.infinity)); // Fails. assert(!approxEqual(3, 0)); assert(approxEqual(3, 3)); assert(approxEqual(3.0, 3)); assert(approxEqual([3, 3, 3], 3.0)); assert(approxEqual([3.0, 3.0, 3.0], 3)); int a = 10; assert(approxEqual(10, a));
Function approxEqual
Computes whether is approximately equal to lhs
admitting a maximum relative difference rhs and a
maximum absolute difference maxRelDiff.
maxAbsDiff
If the two inputs are ranges, returns true if and
only if the ranges have the same number of elements and if approxEqual evaluates to approxEqualtrue for each pair of elements.
Prototype
bool approxEqual(T, U, V)( T lhs, U rhs, V maxRelDiff, V maxAbsDiff = 1e-05 );
Authors
Walter Bright, Don Clugston, Conversion of CEPHES math library to D by Iain Buclaw