June 27, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #10 from Walter Bright <bugzilla@digitalmars.com> 2011-06-27 14:51:23 PDT ---
(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?

> 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.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #11 from yebblies <yebblies@gmail.com> 2011-06-27 20:40:16 PDT ---
(In reply to comment #10)
> 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.

This report has always been asking for a bitwise comparion, which is (as far as I can tell) how every other type is treated by 'is'.

The use case I can remember being discussed is using 'v is float.init' to determine if a floating point value is uninitialized or is a nan due to the result of a calculation.

This seems to be the reason float.nan and float.init have different payloads in the first place.

Currently this fails:

struct A { float f; }
A a;
A b;
b.f = float.nan;
assert((a is b) is (a.f is b.f));

Making 'is' for floating point types consistent with 'is' for other types seems to me like a better move than introducing a new special case.

Maybe Steven or Don have an opinion on this feature they asked for? 'isIdentical' seems to do a straight bitwise comparison.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #12 from Walter Bright <bugzilla@digitalmars.com> 2011-06-27 21:08:47 PDT ---
(In reply to comment #11)
> Making 'is' for floating point types consistent with 'is' for other types seems to me like a better move than introducing a new special case.

The current behavior matches template argument matching. Making it different from such will introduce all kinds of anomalous behavior.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #13 from yebblies <yebblies@gmail.com> 2011-06-27 21:25:22 PDT ---
(In reply to comment #12)
> The current behavior matches template argument matching. Making it different from such will introduce all kinds of anomalous behavior.

Fair enough.  I'm not sure which way is more useful, but they should definitely match.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #14 from Don <clugdbug@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: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #15 from Walter Bright <bugzilla@digitalmars.com> 2011-06-28 02:17:47 PDT ---
(In reply to comment #14)
> I use it all the time, mainly for distinguishing between +0.0 and -0.0

'is' does distinguish between +0 and -0. Just not -Nan and +Nan, nor the Nan payloads.

> 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.

I believe those are entirely different situations. The sign of 0 has a mathematical meaning to fp arithmetic, the sign/payload of Nan does not.

> 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

I didn't know that. But it's worth noting that SANE has been dropped.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #16 from Don <clugdbug@yahoo.com.au> 2011-06-28 04:43:29 PDT ---
(In reply to comment #15)
> (In reply to comment #14)
> > I use it all the time, mainly for distinguishing between +0.0 and -0.0
> 
> 'is' does distinguish between +0 and -0. Just not -Nan and +Nan, nor the Nan payloads.

Then I don't understand the reasoning. I don't think the payload NaN behaviour is terribly important, but being able to do bitwise compare gives an _enormous_ speed benefit.

Note that it isn't possible to create a NaN with a payload at compile time, so I don't think that the argument based on template behaviour is relevant -- as I see it, either behaviour is reasonable.

> > 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.
> 
> I believe those are entirely different situations. The sign of 0 has a mathematical meaning to fp arithmetic, the sign/payload of Nan does not.

Yes, but my argument was the other way around: if you're going to special trouble with -0, you should deal with NaNs as well. But now, if you haven't given -0 special treatment, why slow down 'is' for the sake of the incredibly obscure NaN payload case?

Why not just say, "it does a bitwise compare, which is fast but may give unexpected answers in the case of negative zero and NaNs"?

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #17 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-06-28 04:56:43 PDT ---
(In reply to comment #11)
> The use case I can remember being discussed is using 'v is float.init' to determine if a floating point value is uninitialized or is a nan due to the result of a calculation.
> 
[snip]
> 
> Maybe Steven or Don have an opinion on this feature they asked for? 'isIdentical' seems to do a straight bitwise comparison.

Quite simply, the above (v is float.init) is my use case.  In some parts of the code, the runtime is responsible for default initializing data.  I wanted to verify that my code was properly initializing the data to T.init.

This is impossible without casting the value to a ubyte[] array to do a comparison (and even then, it's not quite right, because you can have garbage data in some cases).

But it makes no sense to me for is to ever do anything but a bitwise compare.

In other words, given any type T (and I mean any type T):

foo(T t)
{
assert(t is t);
}

should always pass.  It makes no sense to me for is to do anything else -- it's low-level bitwise comparison that bypasses any operators.

To make this true for every type *except* floating point types seems like a huge inconsistency.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
June 28, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #18 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-06-28 05:02:11 PDT ---
(In reply to comment #7)
> Reopening as the commit above will cause the following assert to fail: static assert(real.init !is real.nan);

If they are not the same bit pattern, I think this is fine.  is should be a bitwise compare.  I don't know enough about floating point to know whether they are the same bit pattern.

In my understanding of floating point, this means that:

if(x is typeof(x).nan) ...

is not wise code -- it may fail if the exact nan bitpattern is different (my understanding is that nan has multiple representations).  While it may be unintuitive, that is no fault of D -- floating point is sometimes very unintuitive.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
July 18, 2011
http://d.puremagic.com/issues/show_bug.cgi?id=3632



--- Comment #19 from Steven Schveighoffer <schveiguy@yahoo.com> 2011-07-18 06:37:46 PDT ---
(In reply to comment #18)
> (In reply to comment #7)
> > Reopening as the commit above will cause the following assert to fail: static assert(real.init !is real.nan);
> 
> If they are not the same bit pattern, I think this is fine.  is should be a bitwise compare.  I don't know enough about floating point to know whether they are the same bit pattern.

I think I misread the above.  If the above assert fails, and they are different bit patterns, this is definitely a problem.  Two different bit patterns should fail to compare as equal.

== can do the intelligent standards-conforming thing, but 'is' should do bitwise comparison.  If it doesn't, then you cannot use it as a tool to verify low-level manipulation (such as allocating memory with a pre-defined value) is working.  And I don't see the point of using 'is' on floating points otherwise, it's misleading.

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