[Issue 3632] modify float is float to do a bitwise compare

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Jun 28 01:13:22 PDT 2011


http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #14 from Don <clugdbug at yahoo.com.au> 2011-06-28 01:08:25 PDT ---
(In reply to comment #10)
> (In reply to comment #9)
> > (In reply to comment #8)
> > > This is intended. All nans are regarded as the same (even signalling and
> > > non-signalling).
> > So we have to use std.math.isIdentical() to tell apart floating point values on
> > the base of the their bit patterns.
> 
> Do you have any need for this?

I use it all the time, mainly for distinguishing between +0.0 and -0.0

But I think this has perhaps not been understood in this discussion: bitwise
compare doesn't just affect NaN, it also means that +0.0 !is -0.0.

There definitely seems value in changing 'is' so that 'A is A' is true for any
A. Note that any user-defined type can define == to always return false, so it
isn't true that 'A is B' implies 'A==B', so we don't lose consistency in that
way.

But it's reasonable to argue that '+0.0 is -0.0' should return true, and if you
do that, then 'NaN is NaN' should also return true, regardless of the payload.

> > Related: I think almost no one uses the NaN payloads because (beside being a
> > niche need) almost no language gives easy and explicit support to manage those
> > payloads (while in std.math there are functions like getNaNPayload).
> 
> I've been around numerics for 35 years now, and I've never seen a use for NaN
> payloads. I've never seen anyone even propose a use. Until then, I suspect
> supporting such would just cause problems.

NaN payloads were used extensively in Apple's SANE, to distinguish different
error types. Eg,

http://doc.4d.com/4D-Language-Reference-11.6/Error-Codes/SANE-NaN-Errors-1-255.300-206143.en.html

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list