-0 assigned to a FP variable
Walter Bright
newshound2 at digitalmars.com
Sun Jan 9 21:37:15 PST 2011
bearophile wrote:
> A bug I've introduced once in my D code, are you able to spot it?
>
> void main() { double x = +0; double y = -0; }
>
>
> The bug: 'y' isn't the desired double -0.0
>
> To avoid this bug DMD may keep the -0 and +0 integer literals represented in
> two distinct ways, so they have two different values when/if assigned to a
> floating point. (But here D will behave a little differently from C). An
> alternative is to just add a warning to DMD. A third possibility is to just
> ignore this probably uncommon bug :-)
This is not a bug in the language or compiler. While there is such a thing as
-0.0, there is no such thing as -0 as being distinct from 0. If you want to flag
mathematical no-ops as errors, what's next? a+0 is an error, too?
More information about the Digitalmars-d
mailing list