[Mono-list] Mono and .Net Floating Point Inconsistencies
kornelpal at gmail.com
Sat Jan 17 18:58:02 EST 2009
DLLs are Windows specific are you sure you actually executed setFloats()
If you are unable to solve this issue using control flags we can't
figure out what your problem is without providing us a test case that
exhibits this behavior.
Please create a source code (can be as small as your wish) that can be
compiled without modifications so that other people will be able to
reproduce the problem.
> I tried the FPU flags as follows:
> 1.Compiled the following file to a dll using gcc on a test linux system:
> #include <fpu_control.h>
> void setFloats()
> fpu_control_t desired = _FPU_MASK_DM | _FPU_MASK_UM | _FPU_MASK_PM
> |_FPU_DOUBLE | _FPU_RC_NEAREST ;
> _FPU_SETCW( desired);
> 2.Added the following code to my main class in the C# code:
> public static extern void setFloats();
> 3.Called setFloats() before any other code.
> The end results were the exact same as all my other mono runs and thus
> different than my .NET runs. The C code without the masks caused my program
> to throw divided by zero exceptions from Console.Writeline() and
> File.Exists(). Are there other flags I can try or does the fact that this
> happens on Windows mono and Linux mono point to something other than the FPU
> setup? I'll keep looking for the exact spot where inconsistencies start to
> happen and just to try it, I'm compiling mono 2.2 on a test machine to see
> if that changes anything (everything so far has been on 2.0.2).
> Kornél Pál wrote:
>> Please try the FPU flags suggested John to see if that solves your
>> problem, modifying the control flags could be added to x86 versions of
>> Mono so you wouldn't have to modify them manually.
>> ddambro wrote:
>>> The code is compiled for x86 in Windows, and the problems I describe
>>> even using mono for Windows. That is, on every computer I've tried so
>>> regardless of OS and processor type, all of the mono runs produce the
>>> results and all of the .NET runs produce the same results, but these
>>> are different from each other. This includes a 64-bit Vista machine
>>> the x86 code in .NET and mono (installed as x86). How would this affect
>>> your suggested fix? Also I noticed a fairly significant speed up when I
>>> converted all my doubles to floats in this code a few years ago, would
>>> fix undo that? mono already runs the code MUCH slower than .NET so I'd
>>> to get another performance hit.
>>> Dallman, John-2 wrote:
>>>>> when I take the same binary and run it with the same inputs it
>>>>> produces different outputs if it is run on mono and .Net.
>>>> This is with Mono on Linux, and .NET on Windows? The executable
>>>> is 32-bit .NET code?
>>>> I suspect that you've hit a misfeature that exists for most
>>>> floating-point code on 32-bit x86 Linux.
>>>> The code to be run in the C function is:
>>>> #include <fpu_control.h> /* Mask the Denormal, Underflow and Inexact
>>>> leaving Invalid, Overflow and
>>>> Zero-divide active.
>>>> Set precision to standard doubles,
>>>> and round-to-nearest. */
>>>> fpu_control_t desired = _FPU_MASK_DM | _FPU_MASK_UM | _FPU_MASK_PM |
>>>> _FPU_DOUBLE | _FPU_RC_NEAREST ;
>>>> _FPU_SETCW( desired);
>>>> This needs to be a C function because everything in uppercase in
>>>> that code is a macro, from fpu_control.h. You may want to leave out
>>>> enabling floating point traps, in which case the code becomes:
>>>> #include <fpu_control.h> /* Set precision to standard doubles, and
>>>> round-to-nearest. */
>>>> fpu_control_t desired = _FPU_DOUBLE | _FPU_RC_NEAREST ;
>>>> _FPU_SETCW( desired);
>>>> It would be good, really, if Mono had a standard call for setting
>>>> up consistent floating-point on all its platforms.
>>>> John Dallman
>>>> Parasolid Porting Engineer
>>>> Siemens PLM Software
>>>> 46 Regent Street, Cambridge, CB2 1DP
>>>> United Kingdom
>>>> Tel: +44-1223-371554
>>>> john.dallman at siemens.com
>>>> Mono-list maillist - Mono-list at lists.ximian.com
>> Mono-list maillist - Mono-list at lists.ximian.com
More information about the Mono-list