[Bug 45] New: Bug in conversion of floating point literals
Thomas Kuehne
thomas-dloop at kuehne.cn
Wed Mar 15 03:08:57 PST 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
d-bugmail at puremagic.com schrieb am 2006-03-13:
> Literals are treated (incorrectly) as type real when used in an initialiser,
> but as type double when used in an assignment. This is an extremely difficult
> bug to track down, as it is essentially bad code generation, so I've marked it
> as critical.
>
> void main()
> {
> real a = 3.40483; // this is treated as 3.40483L
> real b;
> b = 3.40483;
> assert(a==b);
> }
Strictly speaking the code above behaves correctly.
http://www.digitalmars.com/d/float.html
# For floating point operations and expression intermediate values, a
# greater precision can be used than the type of the expression. Only the
# minimum precision is set by the types of the operands, not the maximum.
The documentation doesn't require an expression to always use the same
"excessive" precision.
Never the less, the shown behaviour is annoying - either expand the
literal's precision on all ocasion or never.
Thomas
-----BEGIN PGP SIGNATURE-----
iD8DBQFEGALe3w+/yD4P9tIRArsSAKCYGMgpxTsDAS+JjXovgDLk3gu0KQCg0gIL
rV7NfmeNKjFgjvCAGKwfUqw=
=wbYB
-----END PGP SIGNATURE-----
More information about the Digitalmars-d-bugs
mailing list