Thread overview | |||||
---|---|---|---|---|---|
|
August 10, 2005 Negative numbers are treated as Positive in compares. | ||||
---|---|---|---|---|
| ||||
// 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 |
August 10, 2005 Re: Negative numbers are treated as Positive in compares. | ||||
---|---|---|---|---|
| ||||
Posted in reply to David L. Davis | "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. |
August 13, 2005 Re: Negative numbers are treated as Positive in compares. | ||||
---|---|---|---|---|
| ||||
Posted in reply to David L. Davis Attachments: | 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 |
Copyright © 1999-2021 by the D Language Foundation