C#C
C#2y ago
thegu5

Float (signed) number comparisons compiled to unsigned version of instruction

Why does
    public bool lteq(float a, float b) {
        return a <= b;
    }

compile to
        IL_0000: ldarg.1
        IL_0001: ldarg.2
        IL_0002: cgt.un
        IL_0004: ldc.i4.0
        IL_0005: ceq
        IL_0007: ret

whereas
    public bool not(float a, float b) {
        return !(a > b);
    }

compiles to the same thing but with cgt instead of cgt.un? Are these two expressions not equivalent? I'm also confused why it's using .un for two signed numbers that are ordered

sharplab: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBLANgHwAEAmARgFgAoQgZgAIS6BhOgbyrs4fuAglzoA7CBgAUAM1wQAhhjrS0dSTLnAAlGw5dthAOx0AhKOl0AfHXUBuLZwC+N7hb4DcGGAEcJU2fMXKf6pqU2jr6JgA8ALwW1sFc9pS2QA
C#/VB/F# compiler playground.
Was this page helpful?