Comparing double and float values

Matthew Ong ongbp at yahoo.com
Thu May 12 03:39:43 PDT 2011


Hi jen,

If you really want to to compare bit by bit it should be possible to
cast the floating point values and then perform the comparison.

Please see the URL:
http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Double.html#doubleToRawLongBits%28double%29

Casting does that looses the value decimal point value?

The most important
Returns a representation of the specified floating-point value according to the
IEEE 754 floating-point "double format" bit layout, preserving Not-a-Number (NaN)
values.

underneath the source code, it is just C code:

union {
    double dval;
    long lval;
}

They fill dval to get lval and vs.

That is important if u use that for searching within a Hashtable like:

double[string] myvals; // look for the key string using double?




More information about the Digitalmars-d mailing list