http://d.puremagic.com/issues/show_bug.cgi?id=3928
Summary: Comparing imaginaries with reals produces results that are inconsistent Product: D Version: 2.041 Platform: x86 OS/Version: Windows Status: NEW Severity: normal Priority: P2 Component: DMD AssignedTo: nob...@puremagic.com ReportedBy: crimson.ma...@gmail.com --- Comment #0 from Aldo Nunez <crimson.ma...@gmail.com> 2010-03-10 12:04:36 PST --- Comparing an imaginary number like an ifloat with a real one like a float: 1. Has results that differ at compile time and runtime. 2. At runtime is done in the wrong order. 3. Doesn't seem to be very meaningful, given that you can't compare complex numbers. With respect to each issue above, here are some more details. 1. Different results at runtime and compile time. At compile time, if the left is imaginary, then we take the imaginary part of the right side and compare the two. If the left side is real, then we take the real part of the right side and compare. All of this is as seen in constfold.c. At runtime, we turn both sides into complex numbers by making a missing part zero. Then, we compare the imaginary parts, and if they're equal, compare the real parts. 2. Wrong order at runtime. In the runtime comparison described in #1 what's actually compared is right to left instead of left to right. If my program has "a < b", then "b < a" is checked. 3. Meaning? Comparisons where at least one side is a complex number are not allowed in D. As such, is it meaningful to allow the comparisons described here, given that such numbers are treated as complex numbers and compared? Note, all of this is strictly where one side of a compare expression is an imaginary number and the other is a real number. Here's a sample program: import std.stdio; void main() { cfloat cf1 = 1 + 2i; cfloat cf2 = 3 + 4i; ifloat if2 = 1i; float f2 = 3; ifloat if3 = 4i; float f3 = 2; ifloat if4 = 5i; float f4 = 5; writeln( "--- < ---" ); writeln( if2 < f2 ); writeln( f2 < if2 ); writeln( if3 < f3 ); writeln( f3 < if3 ); writeln( if4 < f4 ); writeln( f4 < if4 ); writeln( 1i < 3 ); writeln( 3 < 1i ); writeln( 4i < 2 ); writeln( 2 < 4i ); writeln( 5i < 5 ); writeln( 5 < 5i ); writeln( "--- == ---" ); writeln( if2 == f2 ); writeln( f2 == if2 ); writeln( if3 == f3 ); writeln( f3 == if3 ); writeln( if4 == f4 ); writeln( f4 == if4 ); writeln( 1i == 3 ); writeln( 3 == 1i ); writeln( 4i == 2 ); writeln( 2 == 4i ); writeln( 5i == 5 ); writeln( 5 == 5i ); writeln( "--- > ---" ); writeln( if2 > f2 ); writeln( f2 > if2 ); writeln( if3 > f3 ); writeln( f3 > if3 ); writeln( if4 > f4 ); writeln( f4 > if4 ); writeln( 1i > 3 ); writeln( 3 > 1i ); writeln( 4i > 2 ); writeln( 2 > 4i ); writeln( 5i > 5 ); writeln( 5 > 5i ); } -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------