-0 assigned to a FP variable

Justin Johansson noreply at jj.com
Mon Jan 10 03:29:46 PST 2011


On 10/01/11 11:27, 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 :-)
>
> Bye,
> bearophile

 > 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 butterfly answers back to you.

There is no bug.  Did you mean

<code>
void main() {
      double x = +0.0;
      double y = -0.0;
}
</code>  ?

Are you able to spot it?

Is it still a bug?

Cheers
Justin


More information about the Digitalmars-d mailing list