[Mono-dev] Simple floating maths problem

Stuart Fraser stuart at stuartfraser.net
Thu Apr 29 18:21:56 EDT 2010


HI All,

I'm currently working on some code for HPC benchmarking using a number of languages and runtimes but am primarily focussing on C#. During my coding I have come across some inconsistencies between results between calculated in Mono vs .Net (and C /Java), there may be a number of reasons for this but I was after a sanity check before I start looking into the mono runtime code...

Basically I have pulled out some of the internal values/working and problem is thus: 

            int fact = 50000;
            float[] tList = { 0.95864f, 0.89374f, 0.89092f, 0.89716f, 0.4191f, 0.79782f };

            foreach (float val in tList)
            {
                int comp = (int)(val * fact);
                Console.WriteLine("{0:g} * {1:d} = {2:d}", val, fact, comp);
            }

Mono results:
0.95864 * 50000 = 47931
0.89374 * 50000 = 44686
0.89092 * 50000 = 44545
0.89716 * 50000 = 44857
0.4191 * 50000 = 20954
0.79782 * 50000 = 39890

.Net results :
0.95864 * 50000 = 47932
0.89374 * 50000 = 44687
0.89092 * 50000 = 44546
0.89716 * 50000 = 44858
0.4191 * 50000 = 20955
0.79782 * 50000 = 39891

Obviously precision required is very important but this only appears to be a problem on Mono. 
I have tested this with Mono 2.6.2 and 2.6.4 on 
 - OpenSUSE 11.2 (x64) AMD Athlon x64 
 - Windows 7 (x64) Intel  i7
 - Cray XT4h (x64) AMD Opteron :) 
I have tried the code being run checked and unchecked, I have compiled with .net and run the executable under mono and done a clean mono build and test,
I have looked through the bugzilla but haven't seen anything that matches this, its late and I'm tired is this a bug in the mono jit/runtime?
Suggestions on where to look for a fix?

Regards
Stuart


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________


More information about the Mono-devel-list mailing list