www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Comparing arrays of floats?

reply Straivers <straivers98 gmail.com> writes:
Forgive me if this has already been discussed, but how are arrays 
of floating point numbers compared in D? i.e. Is it a bit-by-bit 
comparison, is the std.math.approxEqual function get called for 
each element, or is it byte-by-byte across the entire array?

-Straivers
Oct 09 2015
next sibling parent anonymous <anonymous example.com> writes:
On Saturday 10 October 2015 00:14, Straivers wrote:

 Is it a bit-by-bit comparison,
no
 is the std.math.approxEqual function get called for 
 each element,
no
 or is it byte-by-byte across the entire array?
no After comparing the lengths, the elements are checked for equality one by one, using the usual `==` operator. `==` is different from bitwise comparison. For example, -0f and +0f are `==` equal but have different bits, and NaNs are equal no nothing, not even themselves.
Oct 09 2015
prev sibling parent Meta <jared771 gmail.com> writes:
On Friday, 9 October 2015 at 22:14:09 UTC, Straivers wrote:
 Forgive me if this has already been discussed, but how are 
 arrays of floating point numbers compared in D? i.e. Is it a 
 bit-by-bit comparison, is the std.math.approxEqual function get 
 called for each element, or is it byte-by-byte across the 
 entire array?

 -Straivers
If you want to compare them with approxEqual, you can do: arr1.equal!approxEqual(arr2)
Oct 09 2015