bearophile wrote:
Don:
Do you know what cast(ulong) is doing here?
Turning it from a signalling nan to a quiet nan.

I really really didn't know this. Is this written somewhere in the D docs? :-)

It's the way signalling nans work. _Any_ use of them raises a floating point exception, then turns them into a quiet NaN.

You mean, because it's a negative nan?

Yes, I mean that. Is a negative nan a meaningful concept?

It's part of the payload of the nan.

Is it a true negative nan coming from the division of two positive values, or it's just a bug of writeln, or is it something completely different?


The signalling nans get triggered in the 'double x; ' line.

(You are often two steps forward compared to my thought patterns, so please be 
patient with me)
In this program the FP register is modified after that definition line, so I 
don't expect 'double x; ' to trigger an hardware exception.

Unfortunately the way the backend deals with it at present is to do:
double x;
x = double.init;
which is wrong because it involves an assignment, which may or may not trigger a floating point exception, depending on your cpu*. If it triggers one, then x contains a quiet nan, instead of a signalling one! So the signalling nan idea doesn't quite work yet.

* it actually is documented in Intel/AMD docs for the FLD and FSTP instructions, but you have to read it _very_ carefully to notice. As far as I can tell, nobody has noticed the difference before. I only discovered it through experiment.

Reply via email to