Le 10/01/2011 01:27, bearophile a écrit :
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
Hi,
Do you suggest the compiler should guess you want -0.0 and convert 0 to
double before applying the unary minus operator ?
I suppose such a fix would be likely to create many more bugs than the
one it is suppose to solve.
I don't have a clue on what kind of user code needs to differentiate 0.0
and -0.0 fp litterals, but I humbly suppose that it must be kind of rare.