[Mono-devel-list] floating point compares
Paolo Molaro
lupus at ximian.com
Fri Mar 7 12:18:59 EST 2003
Posted just to mono-devel-list, there is not point in cross-posting.
On 03/06/03 yoros at wanadoo.es wrote:
> using System;
>
> public class EntryPoint {
>
> public static void Main (string[] args) {
>
> double a = Double.NaN;
> double b = 1.0;
>
> if (a == a)
> Console.WriteLine("NAN == NAN");
> if (a < a)
> Console.WriteLine("NAN < NAN");
> if (a > a)
> Console.WriteLine("NAN > NAN");
> if (a <= a)
> Console.WriteLine("NAN <= NAN");
> if (a >= a)
> Console.WriteLine("NAN >= NAN");
[...]
There are at least two bugs, one in mcs and one in the runtime:
mcs generates the following code to implement bool val = a <= a:
IL_0052: ldloc.0
IL_0053: ldloc.0
IL_0054: cgt
IL_0056: ldc.i4.0
IL_0057: ceq
while cvs generates:
IL_004d: ldstr "NAN <= NAN: {0}"
IL_0052: ldloc.0
IL_0053: ldloc.0
IL_0054: cgt.un
IL_0056: ldc.i4.0
IL_0057: ceq
and for bool val = a >= a:
IL_0068: ldloc.0
IL_0069: ldloc.0
IL_006a: clt
IL_006c: ldc.i4.1
IL_006d: sub
versus the csc output:
IL_0068: ldloc.0
IL_0069: ldloc.0
IL_006a: clt.un
IL_006c: ldc.i4.0
IL_006d: ceq
The output from the ms runtime when running the code compiled by mcs
is the same as with the mono runtime.
I have filed http://bugzilla.ximian.com/show_bug.cgi?id=39314
to track the bug.
lupus
--
-----------------------------------------------------------------
lupus at debian.org debian/rules
lupus at ximian.com Monkeys do it better
More information about the Mono-devel-list
mailing list