www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - Negative numbers are treated as Positive in compares.

reply David L. Davis <SpottedTiger yahoo.com> writes:
// WinXP with D v0.129 (and v0.128)
At first, I couldn't understand why my D code was falling into areas of code it
shouldn't have...until I discovered that the negative numbers were being treated
as if they were positive numbers in my compares. As the example below shows:

# //negcompare.d
# private import std.stdio;
# int main()
# {    
#     writefln("main() : (-128 >= 0)=%s, (-128 <= 0)=%s", 
#              (-128 >= 0 ? "true" : "false"),
#              (-128 <= 0 ?  "true" : "false"));     
#
#     writefln("main() : (128 >= 0)=%s, (128 <= 0)=%s", 
#              (128 >= 0 ? "true" : "false"),
#              (128 <= 0 ?  "true" : "false"));
#              
#     return 0;
# }

Output:
--------
C:\dmd>dmd negcompare.d
C:\dmd\bin\..\..\dm\bin\link.exe negcompare,,,user32+kernel32/noi;

C:\dmd>negcompare
main() : (-128 >= 0)=true, (-128 <= 0)=false
main() : (128 >= 0)=true, (128 <= 0)=false

C:\dmd>

David L.

-------------------------------------------------------------------
"Dare to reach for the Stars...Dare to Dream, Build, and Achieve!"
-------------------------------------------------------------------

MKoD: http://spottedtiger.tripod.com/D_Language/D_Main_XP.html
Aug 10 2005
next sibling parent "Jarrett Billingsley" <kb3ctd2 yahoo.com> writes:
"David L. Davis" <SpottedTiger yahoo.com> wrote in message 
news:dddcir$ds4$1 digitaldaemon.com...
 // WinXP with D v0.129 (and v0.128)
 At first, I couldn't understand why my D code was falling into areas of 
 code it
 shouldn't have...until I discovered that the negative numbers were being 
 treated
 as if they were positive numbers in my compares. As the example below 
 shows:

Oh dear. Confirmed 0.129 Windows.
Aug 10 2005
prev sibling parent =?UTF-8?B?VGhvbWFzIEvDvGhuZQ==?= writes:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

David L. Davis schrieb:

 // WinXP with D v0.129 (and v0.128)
 At first, I couldn't understand why my D code was falling into areas of code it
 shouldn't have...until I discovered that the negative numbers were being
treated
 as if they were positive numbers in my compares. As the example below shows:
 
 # //negcompare.d
 # private import std.stdio;
 # int main()
 # {    
 #     writefln("main() : (-128 >= 0)=%s, (-128 <= 0)=%s", 
 #              (-128 >= 0 ? "true" : "false"),
 #              (-128 <= 0 ?  "true" : "false"));     
 #
 #     writefln("main() : (128 >= 0)=%s, (128 <= 0)=%s", 
 #              (128 >= 0 ? "true" : "false"),
 #              (128 <= 0 ?  "true" : "false"));
 #              
 #     return 0;
 # }
 
 Output:
 --------
 C:\dmd>dmd negcompare.d
 C:\dmd\bin\..\..\dm\bin\link.exe negcompare,,,user32+kernel32/noi;
 
 C:\dmd>negcompare
 main() : (-128 >= 0)=true, (-128 <= 0)=false
 main() : (128 >= 0)=true, (128 <= 0)=false
 

Added to DStress as http://dstress.kuehne.cn/run/o/opCmp_05_A.d http://dstress.kuehne.cn/run/o/opCmp_05_B.d http://dstress.kuehne.cn/run/o/opCmp_05_C.d http://dstress.kuehne.cn/run/o/opCmp_05_D.d http://dstress.kuehne.cn/run/o/opCmp_05_E.d http://dstress.kuehne.cn/run/o/opCmp_05_F.d Thomas -----BEGIN PGP SIGNATURE----- iD8DBQFC/l773w+/yD4P9tIRAiQuAJ4s5Az4o9REpHemYIuCONAE3ueKlwCfXA6l MXuOL35ZbJgsgziMxhbNZo8= =x4tp -----END PGP SIGNATURE-----
Aug 13 2005