language: C# (mono-2.8)
date: 695 days 11 hours ago
link:
visibility: public
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Program
{
    static ulong EncodeDouble(double d)
    {
        long ieee = System.BitConverter.DoubleToInt64Bits(d);
        ulong widezero = 0;
        return ((ieee < 0)? widezero: ((~widezero) >> 1)) ^ (ulong)~ieee;
    }
 
    static void Test(double a, double b)
    {
        System.Console.WriteLine(a.ToString() + " <=> " + b.ToString() + (a.CompareTo(b) == EncodeDouble(a).CompareTo(EncodeDouble(b))? " : pass" : " : fail"));
    }
 
    static void Main()
    {
        Test(2, 3);
        Test(2, 20);
        Test(2, 0.5);
        Test(2, -2);
        Test(-2, -3);
        Test(-2, -20);
        Test(-2, -0.5);
    }
}