© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•2y ago•
4 replies
thegu5

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

Why does
    public bool lteq(float a, float b) {
        return a <= b;
    }
    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
        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);
    }
    public bool not(float a, float b) {
        return !(a > b);
    }

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

sharplab: https://sharplab.io/#v2:EYLgxg9gTgpgtADwGwBYA0AXEBLANgHwAEAmARgFgAoQgZgAIS6BhOgbyrs4fuAglzoA7CBgAUAM1wQAhhjrS0dSTLnAAlGw5dthAOx0AhKOl0AfHXUBuLZwC+N7hb4DcGGAEcJU2fMXKf6pqU2jr6JgA8ALwW1sFc9pS2QA
SharpLab
C#/VB/F# compiler playground.
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ LLVMSharp create signed and unsigned constants.
C#CC# / help
3y ago
Using instruction
C#CC# / help
4y ago
❔ sorting by version number
C#CC# / help
3y ago