Bug 26213 - [iOS] (int) Math.Pow ((double)10, (double)32) returns -1 in Release build on iPhone 5s & iPhone 6 running iOS 8.0.2
Summary: [iOS] (int) Math.Pow ((double)10, (double)32) returns -1 in Release build on ...
Status: RESOLVED UPSTREAM
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: XI 8.6.0
Hardware: PC Mac OS
: Highest normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-20 17:06 UTC by Kent Green [MSFT]
Modified: 2015-01-23 09:21 UTC (History)
4 users (show)

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


Attachments
Test Case & Log files (68.35 KB, application/zip)
2015-01-20 17:06 UTC, Kent Green [MSFT]
Details


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:
RESOLVED UPSTREAM

Description Kent Green [MSFT] 2015-01-20 17:06:13 UTC
Created attachment 9426 [details]
Test Case & Log files

---Overview---
From this priority desk case:
https://xamarin.desk.com/agent/case/118986

Customer reports that (int) Math.Pow ((double)10, (double)32) returns -1 in Release build on iPhone 5s & iPhone 6 running iOS 8.0.2, instead of the expected value of -2147483648. 

The customer notes that the code works as expected in the iOS Simulators, and Debug mode for the iPhone 5s.

---Snippet to reproduce issue---
>public override bool FinishedLaunching (UIApplication app, NSDictionary options)
>		{
>			window = new UIWindow (UIScreen.MainScreen.Bounds);
>			var result = (int)Math.Pow ((double)10, (double)32);

>			Console.WriteLine ("Result: {0}", result);
>			window.RootViewController = new UIViewController ();

>			window.MakeKeyAndVisible ();
			
>			return true;
>		}

---Expected results---
The application output should show:
> Result: -2147483648

---Actual Results---
The application output shows:
> Result: -1

---Build Info---
=== Xamarin Studio ===

Version 5.7 (build 661)
Installation UUID: 033d9ed1-df59-4db1-b8a6-a973ee0a8433
Runtime:
Mono 3.12.0 ((detached/a813491)
GTK+ 2.24.23 (Raleigh theme)

Package version: 312000068

=== Xamarin.Android ===

Version: 4.20.0.28 (Enterprise Edition)
Android SDK: /Users/hari/Library/Developer/Xamarin/android-sdk-mac_x86
Supported Android versions:
2.1 (API level 7)
2.2 (API level 8)
2.3 (API level 10)
3.1 (API level 12)
4.0 (API level 14)
4.0.3 (API level 15)
4.3 (API level 18)
4.4 (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Apple Developer Tools ===

Xcode 6.0.1 (6528)
Build 6A317

=== Xamarin.iOS ===

Version: 8.6.0.51 (Enterprise Edition)
Hash: dfb682f
Branch:
Build date: 2015-01-08 13:39:32-0500

=== Xamarin.Mac ===

Not Installed

=== Build Information ===

Release ID: 507000661
Git revision: b70bab61da996da29045ea8ee8aed1a6faedbe78
Build date: 2015-01-05 16:31:31-05
Xamarin addins: 82f6c71490562d6cd125a09287f441902fdac3d7

=== Operating System ===

Mac OS X 10.9.5
Darwin Haris-MacBook-Pro.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

---Additional Info---
The test case was made by Anuj, so I included that along with the customer's log files
Comment 2 Rolf Bjarne Kvinge [MSFT] 2015-01-21 04:17:13 UTC
I can reproduce this in both Debug and Release mode, and both with and without LLVM.

However it only happens with ARM64.

Zoltan, this looks like your area.
Comment 3 Zoltan Varga 2015-01-21 16:06:36 UTC
This seems to be a hardware difference between platforms.

Math.Pow ((double)10, (double)32) is 0x4693b8b5b5056e17, converting it to int on x86 results in
-2147483648 (0x80000000), while on arm64 it results in 2147483647 (0x7fffffff). This can be tested using the following C code:

			long l = 0x4693b8b5b5056e17;
			double d = *(double*)&l;
			int foo = (int)d;

			printf ("X: %lf %d\n", d, foo);
Comment 4 Udham Singh 2015-01-22 06:09:26 UTC
I have checked this issue with Test Case attached in bug and able to reproduce this issue. Please refer the screencast : http://www.screencast.com/t/eGfkl2CkzJF

Environment Info : 

=== Xamarin Studio ===

Version 5.7.1 (build 13)
Installation UUID: ce927b2a-2c07-44c5-b186-09cfdafba6dc
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

=== Apple Developer Tools ===

Xcode 6.1.1 (6611)
Build 6A2008a

=== Xamarin.iOS ===

Version: 8.6.1.9 (Business Edition)
Hash: d8e6436
Branch: 
Build date: 2015-01-18 17:38:20-0500

=== Build Information ===

Release ID: 507010013
Git revision: 8e357d6be321e716f361ebc9591e4cee7f217c21
Build date: 2015-01-15 14:23:22-05
Xamarin addins: a6842a7727f64e956f942b8160f7835c9d9076a4

=== Operating System ===

Mac OS X 10.9.5
Darwin Xamarin76s-Mac-mini.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 5 Sebastien Pouliot 2015-01-23 09:21:13 UTC
Like Zoltan mentioned in comment #3 this is an hardware (CPU) difference that affects any language/runtime. You cannot expect a specific value when casting 10^32 into an int.