Bug 29570 - decimal comparisons look to be broken.
Summary: decimal comparisons look to be broken.
Status: VERIFIED FIXED
Alias: None
Product: Android
Classification: Xamarin
Component: Mono runtime / AOT Compiler (show other bugs)
Version: 5.1
Hardware: Macintosh Mac OS
: Highest critical
Target Milestone: 5.1.1 (C5SR1)
Assignee: Marek Habersack
URL:
: 29948 30025 30033 (view as bug list)
Depends on:
Blocks:
 
Reported: 2015-04-30 01:19 UTC by David Thornley
Modified: 2015-05-13 11:42 UTC (History)
16 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
VERIFIED FIXED

Description David Thornley 2015-04-30 01:19:16 UTC
Basic decimal comparison is broken.

To test I just created a blank android application and placed the code in the activity OnCreate method: -

decimal a = 15;
decimal b = -40;
if(a < b) {
	Console.WriteLine("A < B");
}

The if expression evaluates to true on 5.1 (incorrectly), but false on 4.2 (correctly)

Tested on Android 4.x and Android 5.x devices.

Same code works fine on an OS X Console App (so it looks specific to Xamarin.Android).

=== Xamarin Studio ===

Version 5.9 (build 431)
Installation UUID: 9f6e6705-d675-4efd-bef2-cddbf8240838
Runtime:
	Mono 4.0.0 ((detached/d136b79)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400000143

=== Apple Developer Tools ===

Xcode 6.3.1 (7703)
Build 6D1002

=== Xamarin.iOS ===

Version: 8.10.0.267 (Starter Edition)
Hash: 6481535
Branch: master
Build date: 2015-04-27 04:38:13-0400

=== Xamarin.Android ===

Version: 5.1.0.115 (Business Edition)
Android SDK: /Users/davidthornley/dev/android/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-466.1-11M4716)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-466.1, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 509000431
Git revision: 7560726734fc7267de2fa9abed2509968deefaa8
Build date: 2015-04-17 19:25:48-04
Xamarin addins: 2e772c734ab3148054eae7bf8949f340fdeb5e5e

=== Operating System ===

Mac OS X 10.10.2
Darwin SYD234MBP 14.1.0 Darwin Kernel Version 14.1.0
    Thu Feb 26 19:26:47 PST 2015
    root:xnu-2782.10.73~1/RELEASE_X86_64 x86_64
Comment 1 David Schulte 2015-05-01 15:15:47 UTC
This bug also exists when running under Android 4.4.2. Downgrading to Xamarin.Android 4.20.2 resolves this for now.
Comment 2 David Schulte 2015-05-01 15:24:18 UTC
And to expand on this, decimal/int comparisons, where the integer is automatically converted to decimal are not working either.

Example:

decimal somevar = 38.0m;

if ( somevar < int.Min )
    Console.WriteLine("incorrect result");    // We reach here under Android 4.4.2.
Comment 3 Jonathan Pryor 2015-05-01 17:15:57 UTC
This doesn't repro on monodroid/master 5.1.99.236917422 (mono/master b0e63a8).

This does repro on 5.1.0.220453430 (mono/mono-4.0.0-branch f42a83b1).

There's "only" 1152 commits between those... :-/
Comment 4 David Thornley 2015-05-03 18:39:32 UTC
I have a little more info to add to this... I noticed this same behaviour on mono on raspbian (linux arm) via apt source (http://download.mono-project.com/repo/debian wheezy main). 

The version is "Mono JIT compiler version 4.0.1 (tarball Tue Apr 28 12:05:30 UTC 2015)".

I also found this potentially related issue: https://bugzilla.xamarin.com/show_bug.cgi?id=28344

Sorry I haven't had enough time to drill into it (and hone in my low-level mono debugging skills) - struggling with time :)
Comment 5 Rajneesh Kumar 2015-05-04 13:42:11 UTC
I have checked this issue and able to reproduce this. To reproduce this issue I have followed the help and instruction provided in bug description using following code:

decimal a = 15;
decimal b = -40;
if(a < b) {
    Console.WriteLine("A < B");
}
I observed that the if expression evaluates to true on 5.1 (incorrectly), and false on 4.2 (correctly). below are the screencast for the same:

Screencast: (XA 5.1.0.122):http://www.screencast.com/t/0GT23Tfc
Screencast: (XA 4.20.2.1): http://www.screencast.com/t/lNWh7qnsH

Application Output" https://gist.github.com/Rajneesh360Logica/e13977325fde75b3b783
Build output: https://gist.github.com/Rajneesh360Logica/39c87f5f6078da851272
Ide Logs: https://gist.github.com/Rajneesh360Logica/7069e775accd9e4daf88
Device Logs: https://gist.github.com/Rajneesh360Logica/96b345fc454be42857d9
Android tools Logs: https://gist.github.com/Rajneesh360Logica/8a0e506444da249a5cc0

Environment Info:

=== Xamarin Studio ===

Version 5.9 (build 459)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
	Mono 4.0.1 ((detached/5a0b19f)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 400010024

=== Apple Developer Tools ===

Xcode 6.2 (6776)
Build 6C131e

=== Xamarin.iOS ===

Version: 8.10.1.11 (Enterprise Edition)
Hash: d153c60
Branch: master
Build date: 2015-05-01 11:26:36-0400

=== Xamarin.Android ===

Version: 5.1.0.122 (Enterprise Edition)
Android SDK: /Users/MM/Desktop/android-sdk-macosx
	Supported Android versions:
		2.3    (API level 10)
		4.0.3  (API level 15)
		4.1    (API level 16)
		4.2    (API level 17)
		4.3    (API level 18)
		4.4    (API level 19)
		4.4.87 (API level 20)
		5.0    (API level 21)
Java SDK: /usr
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)

=== Xamarin Android Player ===

Version: Unknown version
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: 2.0.1.21 (Enterprise Edition)

=== Build Information ===

Release ID: 509000459
Git revision: 84bacb5e3f9be4e7b5743c7e58a22cc58007fa5f
Build date: 2015-04-30 04:20:30-04
Xamarin addins: 0e5c28beb42ad379214edfb60ddd18acdbe8fd0c

=== Operating System ===

Mac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
    Sun Aug 17 19:50:11 PDT 2014
    root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64
Comment 6 Mikhail Melnik 2015-05-07 06:26:56 UTC
I think it could be related
Comment 7 Mikhail Melnik 2015-05-07 06:28:41 UTC
Sorry, can't delete previous incomplete comment. 

So, I think it could be related: Math.Abs((decimal)-1) returns -1. 



Xamarin Studio
Version 5.9 (build 431)
Installation UUID: 2ce9ad5e-1900-473f-a546-f3944667d60e
Runtime:
	Microsoft .NET 4.0.30319.34209
	GTK+ 2.24.22 (MS-Windows theme)
	GTK# 2.12.26

Xamarin.Android
Version: 5.1.0 (Indie Edition)
Android SDK: D:\Development\Android\bundle\sdk
	Supported Android versions:
		4.0.3 (API level 15)
		4.2   (API level 17)
		4.3   (API level 18)
		4.4   (API level 19)
		5.0   (API level 21)
Java SDK: C:\Program Files\Java\jdk1.7.0_51
java version "1.7.0_51"
Java(TM) SE Runtime Environment (build 1.7.0_51-b13)
Java HotSpot(TM) 64-Bit Server VM (build 24.51-b03, mixed mode)
Comment 8 info 2015-05-08 03:46:46 UTC
After upgrading to stable 5.1 (big mistake) we now also have this problem.

As we are developing a finance/banking App we are using Decimals a lot. This also means, that if we now compile with 5.1 the App becomes a complete desaster, as the bug occurs in dozens of places where we are performing decimal comparisons.

This is a severe show-stopper Bug to us and it's importance should be changed to CRITICAL.

Heck, the complete Decimal type is broken. Is that what Xamarin considers a Bug with Normal importance?

Andreas
Comment 9 David Schulte 2015-05-08 07:26:39 UTC
Andreas, for now, just downgrade Xamarin.Android to 4.20.2.2 (Xamarin Studio can remain at the latest version). This is what we've done for now and things seem to be ok until they get this fixed.
Dave
Comment 10 David Thornley 2015-05-08 13:00:36 UTC
Confirmed underlying cause is fixed in mono 4.1.0 by bug 28344. Changes in bug 28344 are not present in mono 4.0.1 and subsequently 4.0.0 (as per the original version dump).

Mono should be upgraded (or patched) in Xamarin as a matter of urgency.
Comment 11 Jonathan Pryor 2015-05-08 13:30:41 UTC
Applied on mono-4.0.0-branch/d7f9ffaa and monodroid-5.1-series/850d16df.

This should be fixed in the final Xamarin.Android 5.1.1 release.
Comment 12 Rajneesh Kumar 2015-05-11 06:12:54 UTC
I have checked this issue with the following builds:

Xamarin Studio Version 5.9.2 (build 0)
Installation UUID: 011d70a5-dede-428b-ab04-ef451c2e539d
Runtime:
Mono 4.0.1 ((detached/d7f9ffa)
TK+ 2.24.23 (Raleigh theme)
Package version: 400010029
Xamarin.Android Version: 5.1.1.4 (Business Edition)
java version "1.7.0_65"
Java(TM) SE Runtime Environment (build 1.7.0_65-b17)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-b04, mixed mode)
=== Build Information ===
Release ID: 509020000
Git revision: f97f3598952edca4678fc9fdafffecb68ed24399
Build date: 2015-05-08 11:55:56-04
Xamarin addins: ab18ddff45f507ed74f36c2b65df9aee22e28a56
Operating SystemMac OS X 10.9.5
Darwin MacMini.local 13.4.0 Darwin Kernel Version 13.4.0
Sun Aug 17 19:50:11 PDT 2014
root:xnu-2422.115.4~1/RELEASE_X86_64 x86_64

I observed that this issue does not exist now. Now, I also observed that the expression evaluates to false on 5.1 (correctly). Below are the screencast for the same.

Screencast: http://www.screencast.com/t/klTZkdrs

This issue has been fixed, hence I am closing this issue.

Thanks..!
Comment 13 PJ 2015-05-11 11:55:25 UTC
Hello - due to the nature of this bug we have a pre-release build with the fix available at https://files.xamarin.com/~pjbeaman/mono-android-5.1.1-4.pkg.

Please note that this build has not undergone a full testing cycle, and is considered to be a preview. 

This fix will also be available on the Alpha and Beta updater channels later this week.
Comment 14 Jonathan Pryor 2015-05-11 14:26:33 UTC
*** Bug 29948 has been marked as a duplicate of this bug. ***
Comment 15 Rajneesh Kumar 2015-05-13 07:22:23 UTC
Today, I have checked this issue again with Hot Fix Build Xamarin.Android: 5.1.1.0 on Mac and XVS 3.11.446 on windows and observed that this issue does not exist. Now, I also observed that the expression evaluates to false on 5.1 (correctly). Below are the screencast for the both Mac and windows environment.

Screencast (Mac XS): http://www.screencast.com/t/FJwXgo35jeo
Screencast (Windows XS): http://www.screencast.com/t/fX4hLAUv4LE
Screencast (Windows VS): http://www.screencast.com/t/D7HynZ5Vb

=====Environment Info:=====

Mac: https://gist.github.com/Rajneesh360Logica/58a527d88a41b7a62473
Windows: https://gist.github.com/Rajneesh360Logica/5dc35b563c60dad678c3

Thanks..!
Comment 16 Jonathan Pryor 2015-05-13 10:59:23 UTC
*** Bug 30025 has been marked as a duplicate of this bug. ***
Comment 17 Jonathan Pryor 2015-05-13 11:42:58 UTC
*** Bug 30033 has been marked as a duplicate of this bug. ***