Bug 26219 - Result of cast from double to int is different on Mono amd64 than on .NET and Mono x86
Summary: Result of cast from double to int is different on Mono amd64 than on .NET and...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: JIT (show other bugs)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-20 20:02 UTC by Alexander Köplinger
Modified: 2015-02-12 08:24 UTC (History)
6 users (show)

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


Attachments

Description Alexander Köplinger 2015-01-20 20:02:04 UTC
The following code in a console app:

>unchecked {
>	Console.WriteLine (IntPtr.Size + " " + (int)double.MaxValue);
>	Console.WriteLine (IntPtr.Size + " " + (int)Math.Floor (double.MaxValue));
>}

outputs this:

>.NET:
>
>8 0
>8 -2147483648
>4 0
>4 -2147483648
>
>Mono:
>
>8 -2147483648
>8 0
>4 -2147483648
>4 -2147483648

I noticed this after the System.Timers.Timer source from MS referencesource was imported, as a test started failing on amd64 (see http://wrench.mono-project.com/Wrench/WebServices/Download.aspx?workfile_id=3679509 for an example on Wrench).

Thanks to @davidkarlas and @alexrp for their help.
Comment 1 João Matos 2015-01-21 09:59:13 UTC
I can also reproduce on OSX and Mono for Windows.

> Mono:
> C:\dev\mono\msvc\x64\bin>mono.exe Program.exe
> 8 -2147483648
> 8 0
Comment 2 Zoltan Varga 2015-01-21 15:01:11 UTC
Fixed in mono master 6cf56cbb2f3a95bcacf23f891830ae45a0ebdfa3.
Comment 3 João Matos 2015-01-22 09:39:38 UTC
I can confirm the runtime bug is fixed but I still see some different behaviour with mcs vs. csc, even when running mcs with a Mono with this fix applied.

Looking into it.
Comment 4 João Matos 2015-01-22 10:26:31 UTC
So after some research, me and @akoeplinger concluded that there's a bug in csc.exe when doing double-to-int narrowing conversions. mcs is doing the right thing and Roslyn also seems to have fixed it since:

> <akoeplinger> I tested with roslyn 0.6.4 as used on dotnetfiddle and it does ldc.i4.0, but the roslyn used on another site generates the same as mcs
Comment 6 João Matos 2015-01-30 08:21:34 UTC
I don't think we are shipping 64-bit X86 runtimes in either Windows or OSX so that's why you can't see the option under OSX. And under Windows it must be using the .NET one.

You'll have to compile a 64-bit Mono if you really want to reproduce the fix since it's 64-bit specific.
Comment 8 Ram Chandra 2015-01-30 12:26:14 UTC
Thank you very much Sebastien.

With the help of comment 7 I am able to reproduce this issue.

To verify this issue, I have checked this issue with following builds:

Mac OS X 10.10.0
Xamarin Studio: 5.8 (build 624)
Installation UUID: 6ea47b0d-1852-4aaf-808d-373ff0a5002b
Runtime:
Mono 3.12.0 ((detached/a813491)
GTK+ 2.24.23 (Raleigh theme)
Package version: 312000068
Xcode 6.1 (6604)
Build 6A1052d
Xamarin.iOS: 8.6.1.24 (Business Edition)
=== Build Information ===
Release ID: 508000624
Git revision: fbedf37530cbbf01a75c4cc95557944aa8996aaa
Build date: 2015-01-30 07:52:28-05
Xamarin addins: cb32b8c2c23d061713c5abe206b8ad07723aa77e

Observations: When  I run the test case mentioned in bug description with XI. The output is :

8 -2147483648
8 -2147483648
4 -2147483648
4 -2147483648

This issue has been fixed. Hence I am closing this issue.

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.


Create a new report for Bug 26219 on Developer Community or GitHub if you have new information to add and do not yet see a matching report.

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments


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.

Related Links: