www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - incorrect casting of negative floating point constants (dmd 0.122)

reply zwang <nehzgnaw gmail.com> writes:
<code>
void main(){
const double d = -1.0;
int i = cast(int)d;
assert(-1 == i); // <- assertion failure
}
</code>

Negative "const double" or "const float" is always converted to zero.
May 05 2005
parent Thomas Kuehne <thomas-dloop kuehne.thisisspam.cn> writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

zwang schrieb am Thu, 05 May 2005 15:47:54 +0800:
<code>
 void main(){
 const double d = -1.0;
 int i = cast(int)d;
 assert(-1 == i); // <- assertion failure
 }
</code>

 Negative "const double" or "const float" is always converted to zero.
Added to DStress as http://dstress.kuehne.cn/run/const_20_A.d http://dstress.kuehne.cn/run/const_20_B.d http://dstress.kuehne.cn/run/const_20_C.d http://dstress.kuehne.cn/run/const_20_D.d http://dstress.kuehne.cn/run/const_21_A.d http://dstress.kuehne.cn/run/const_21_B.d http://dstress.kuehne.cn/run/const_21_C.d http://dstress.kuehne.cn/run/const_21_D.d http://dstress.kuehne.cn/run/const_22_A.d http://dstress.kuehne.cn/run/const_22_B.d http://dstress.kuehne.cn/run/const_22_C.d http://dstress.kuehne.cn/run/const_22_D.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFCezkJ3w+/yD4P9tIRAs/PAJ9sOYfhWwb4D9vRIVLYQ1KjrQBpKwCdHQos RAZLPiGSENUUghv6Krmt7ik= =Yr0V -----END PGP SIGNATURE-----
May 06 2005