Bug 17309 - Multiplication of float32 values with conversion gives wrong value
Summary: Multiplication of float32 values with conversion gives wrong value
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: Runtime
Classification: Mono
Component: JIT ()
Version: unspecified
Hardware: PC Mac OS
: --- major
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks: 15463
  Show dependency tree
 
Reported: 2014-01-18 04:22 UTC by Marek Safar
Modified: 2014-01-24 13:58 UTC (History)
3 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 GitHub or Developer Community 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 NOT_ON_ROADMAP

Description Marek Safar 2014-01-18 04:22:03 UTC
using System;

class X
{
    public static void Main (string[] args)
    {
        float a = 0.7f;
        float b = 100.0f;
        Console.WriteLine((int) (a * b));
    }
}

.NET
70

Mono
69
Comment 1 Paolo Molaro 2014-01-24 09:51:49 UTC
This seems to be an issue with the bit representation of 0.7 and the possible fact that the multiplication happens on float32 or float64 values (this depends on optimizations etc). From my tests, even unrelated changes to the test will cause .Net itself to print 69. Besides, 69 is the result also printed with the equivalent C code compiled with gcc, so I don't think this is a mono bug.
Leaving as needinfo for now if you have further insights why this is filed as major.
Comment 2 Marek Safar 2014-01-24 10:51:22 UTC
I don't understand the comment. 

What unrelated changes to the test you made to see 69 printed on .net? I tried to modify the sample but .net still prints 70 (using csc not ilasm or similar)

I don't know what the spec says about multiplication in this case but it looks like .net does it on float32 where we do it on float64.

It's major because compiled code should give same results if we claim we are .net compatible.
Comment 3 Paolo Molaro 2014-01-24 13:18:38 UTC
So, what I did was compile with mono and ran on windows and in both cases it did print 69, which could also point to an issue with parsing/encoding the number. So I compiled it from visual studio and it did print 70, though this might have been an already tweaked test where I replaced the float type with double (and removed the f suffix) because I can't get the original test to print 70 here anymore when compiling and running with .net, it always prints 69.

FWIW, the standard says we should perform the operations on doubles, which is what mono does.

Could you attach the compiled test that returns 70 on .Net? Maybe it depends on the .net version it's been compiled or ran with.
Comment 4 Marek Safar 2014-01-24 13:58:51 UTC
I've done further testing as well and found out that we found .net bug.

Running csc (or mcs compiled code) on 32bit .net prints 69 when running same .exe on 64bits prints 70. If you are saying 69 is the right value then we are fine and .net has bug in 64b JIT.