Thread overview | ||||||
---|---|---|---|---|---|---|
|
March 15, 2010 [Issue 3970] New: Problem with cast -1.0L ==> uint/ulong | ||||
---|---|---|---|---|
| ||||
http://d.puremagic.com/issues/show_bug.cgi?id=3970 Summary: Problem with cast -1.0L ==> uint/ulong Product: D Version: 2.041 Platform: x86 OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nobody@puremagic.com ReportedBy: bearophile_hugs@eml.cc --- Comment #0 from bearophile_hugs@eml.cc 2010-03-15 11:03:36 PDT --- This program compiles and runs with no errors, Don and Aldo Nunez think there are some inconcistancies here: void main() { static assert((cast(ushort)(-1.0L)) == 0xFFFF); static assert((cast(uint)(-1.0)) == 0); static assert((cast(uint)(-1.0L)) == 0); static assert((cast(ulong)(-1.0L)) == 0xbff0000000000000UL); assert((cast(ushort)(-1.0L)) == 0xFFFF); assert((cast(uint)(-1.0)) == 0); assert((cast(uint)(-1.0L)) == 0); assert((cast(ulong)(-1.0L)) == 0xbff0000000000000UL); } Don>The cast(uint) case is clearly a bug.< -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
March 15, 2010 [Issue 3970] Problem with cast -1.0L ==> uint/ulong | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3970 Aldo Nunez <aldonunez1@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |aldonunez1@gmail.com --- Comment #1 from Aldo Nunez <aldonunez1@gmail.com> 2010-03-15 12:38:47 PDT --- It seems like the runtime casting of (float, double, real -> uint) and (float, double -> ulong) can be done simpler, and in a way that would fix the -1.0 -> 0 bug. When converting from float or double to ulong; why can't it be done like real to ulong, where there is a simple conversion in x87 registers plus a fixup for ulong values greater than long.max? When converting from FP to uint; why can't it be done like FP to ushort, where there is a simple conversion to int with x87 registers, and then a truncation? This would make all floating point to integer conversions consistent, and get rid of this bug where an FP -1 turns into an integer 0xFF... in some cases, and in others 0. It should always be 0xFF..., just like a signed integer to unsigned conversion. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 07, 2013 [Issue 3970] Problem with cast -1.0L ==> uint/ulong | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3970 --- Comment #2 from Don <clugdbug@yahoo.com.au> 2013-01-07 09:07:42 PST --- This passes on Linux32 and 64, on 1.076 and 2.061. Also tested on D1.073 so it has been working for quite some time on Linux. Need to check if it is Windows-specific. void main() { static assert((cast(ushort)(-1.0)) == 0xFFFF); static assert((cast(ushort)(-1.0L)) == 0xFFFF); static assert((cast(uint)(-1.0)) == 0xFFFF_FFFF); static assert((cast(uint)(-1.0L)) == 0xFFFF_FFFF); static assert((cast(ulong)(-1.0L)) == 0xFFFF_FFFF_FFFF_FFFFUL); assert((cast(ushort)(-1.0)) == 0xFFFF); assert((cast(ushort)(-1.0L)) == 0xFFFF); assert((cast(uint)(-1.0)) == 0xFFFF_FFFF); assert((cast(uint)(-1.0L)) == 0xFFFF_FFFF); assert((cast(ulong)(-1.0L)) == 0xFFFF_FFFF_FFFF_FFFFUL); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
January 07, 2013 [Issue 3970] Problem with cast -1.0L ==> uint/ulong | ||||
---|---|---|---|---|
| ||||
Posted in reply to bearophile_hugs@eml.cc | http://d.puremagic.com/issues/show_bug.cgi?id=3970 Simen Kjaeraas <simen.kjaras@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |simen.kjaras@gmail.com --- Comment #3 from Simen Kjaeraas <simen.kjaras@gmail.com> 2013-01-07 11:02:17 PST --- Just tested on Windows. First two asserts and static asserts pass, the rest fail. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: ------- |
Copyright © 1999-2021 by the D Language Foundation