Created attachment 1136
problematic code
When I create class with some float variable without value, then call some
method on this class and test float variable for default value, it doesnt work.
My code is in in attachment
Comment #1 by issues.dlang — 2012-08-10T03:00:35Z
If you want to check for NaN, then use std.math.isNaN. As I understand it, there is no guarantee that two NaN values have the same bit pattern (at minimum, you have signed and unsigned NaN, and there may be more variations - I don't remember). isNaN returns true in both cases. So, I don't believe that this is a bug.
Comment #2 by kozzi11 — 2012-08-10T03:19:42Z
(In reply to comment #1)
> If you want to check for NaN, then use std.math.isNaN. As I understand it,
> there is no guarantee that two NaN values have the same bit pattern (at
> minimum, you have signed and unsigned NaN, and there may be more variations - I
> don't remember). isNaN returns true in both cases. So, I don't believe that
> this is a bug.
Thanks for your reply. However I still think it is a bug, because when I assign TYPE.init to variable VAR of type TYPE, and then I compare VAR is TYPE.init, I assumed it returns true;
Comment #3 by clugdbug — 2012-08-15T06:23:41Z
(In reply to comment #2)
> (In reply to comment #1)
> > If you want to check for NaN, then use std.math.isNaN. As I understand it,
> > there is no guarantee that two NaN values have the same bit pattern (at
> > minimum, you have signed and unsigned NaN, and there may be more variations - I
> > don't remember). isNaN returns true in both cases. So, I don't believe that
> > this is a bug.
>
> Thanks for your reply. However I still think it is a bug, because when I assign
> TYPE.init to variable VAR of type TYPE, and then I compare VAR is TYPE.init, I
> assumed it returns true;
Your assumption is not correct. If type.init is a signalling NaN, the bit pattern changes when you access it. It has nothing to do with classes.
More generally,
x = y;
assert (x is y);
Fails if x is floating point and y is a signalling NaN.
When reading from x, the 'quiet' bit of will be set, so that it reads a quiet NaN, not a signalling one.
That's the way the hardware works, the same behaviour applies in any language that uses the hardware.
Comment #4 by kozzi11 — 2012-08-15T07:29:25Z
(In reply to comment #3)
> (In reply to comment #2)
> > (In reply to comment #1)
> > > If you want to check for NaN, then use std.math.isNaN. As I understand it,
> > > there is no guarantee that two NaN values have the same bit pattern (at
> > > minimum, you have signed and unsigned NaN, and there may be more variations - I
> > > don't remember). isNaN returns true in both cases. So, I don't believe that
> > > this is a bug.
> >
> > Thanks for your reply. However I still think it is a bug, because when I assign
> > TYPE.init to variable VAR of type TYPE, and then I compare VAR is TYPE.init, I
> > assumed it returns true;
>
> Your assumption is not correct. If type.init is a signalling NaN, the bit
> pattern changes when you access it. It has nothing to do with classes.
>
> More generally,
>
> x = y;
> assert (x is y);
>
> Fails if x is floating point and y is a signalling NaN.
> When reading from x, the 'quiet' bit of will be set, so that it reads a quiet
> NaN, not a signalling one.
> That's the way the hardware works, the same behaviour applies in any language
> that uses the hardware.
OK, but still I dont understand why others compilers(LDC,GDC) works as I expect and why real type in DMD behave different.
Comment #5 by ibuclaw — 2012-08-15T08:09:25Z
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > > (In reply to comment #1)
> > > > If you want to check for NaN, then use std.math.isNaN. As I understand it,
> > > > there is no guarantee that two NaN values have the same bit pattern (at
> > > > minimum, you have signed and unsigned NaN, and there may be more variations - I
> > > > don't remember). isNaN returns true in both cases. So, I don't believe that
> > > > this is a bug.
> > >
> > > Thanks for your reply. However I still think it is a bug, because when I assign
> > > TYPE.init to variable VAR of type TYPE, and then I compare VAR is TYPE.init, I
> > > assumed it returns true;
> >
> > Your assumption is not correct. If type.init is a signalling NaN, the bit
> > pattern changes when you access it. It has nothing to do with classes.
> >
> > More generally,
> >
> > x = y;
> > assert (x is y);
> >
> > Fails if x is floating point and y is a signalling NaN.
> > When reading from x, the 'quiet' bit of will be set, so that it reads a quiet
> > NaN, not a signalling one.
> > That's the way the hardware works, the same behaviour applies in any language
> > that uses the hardware.
>
> OK, but still I dont understand why others compilers(LDC,GDC) works as I expect
> and why real type in DMD behave different.
GDC calls memcmp() between the two floating values - dunno what DMD does...
Regards
Iain
Comment #6 by kozzi11 — 2019-05-28T19:58:26Z
*** This issue has been marked as a duplicate of issue 3632 ***