Issue with Double.CompareTo()


The method always returns 0, which is obviously not expected.

Issue #565 created.



No luck either with Decimals :frowning:

private static void TestDecimal()
            Decimal a = 20.1M;
            Decimal b = 15.1M;

            var comp = Decimal.Equals(a, b);
            Debug.WriteLine($"Compare {a} to {b} : {comp}");

            a = 20.0M;
            b = 20.0M;
            comp = Decimal.Equals(a, b);
            Debug.WriteLine($"Compare {a} to {b} : {comp}");

            a = -4.7M;
            b = 20.0M;
            comp = Decimal.Equals(a, b);
            Debug.WriteLine($"Compare {a} to {b} : {comp}");

Equals always returns true.

Single.Equals() seems ok, however.

double works as well
but I got this in VS with your example


Thanks. We are looking into it.

@philippeb : it looks like an issue with TinyCLR application. The same application in a .Net Windows form does not show this message.
Btw, 20.0M is a valid decimal, so I don’t understand why it displays this message ?!

However, you say that doubles do work ? That’s not what I see. Could you tell more, please ?

Decimal on embedded device?

I didn’t think decimal is supported but I was curious to investigate further and comment the answer on docs, not here.

Yes, I tried first in a .net winform too and it works as expected
Here is the screen with 2 double values instead of decimal

note that generally, I only use decimal when I deal with some oracle database as the oracle datatype to Net is sometimes tricky

Please confirm that this is full .Net code. Because Double.Equals() is not currently implemented in TinyCLR 2.0 : Issue #502

test done in a TinyClr app

var eq = Equals(a, b); does work.
var eq2 = a.Equals(b); throws CLR_E_UNSUPPORTED_INSTRUCTION exception.

We are both right :smiley:

1 Like