Bug 58085 - Different results on Mono OSX vs Windows-Native for identical sequences of float operations (C#)
Summary: Different results on Mono OSX vs Windows-Native for identical sequences of fl...
Status: RESOLVED ANSWERED
Alias: None
Product: Runtime
Classification: Mono
Component: Interop ()
Version: 5.0 (2017-02)
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-07-11 19:39 UTC by dnbeveridge
Modified: 2017-07-20 14:47 UTC (History)
4 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 ANSWERED

Description dnbeveridge 2017-07-11 19:39:11 UTC
Using Mono 5.0.0.100 vs native windows (Win7U/64), one can receive different results from an identical sequence of float operations.


The following code demonstrates this (C#) by using equality in a float operation (a no-no, but a demonstration none the less):

{
    float high = 2.0F;
    int   L    = 100;
    return (nHigh / L >= 0.02);    // 0.02 is of type System.Double
}

on OSX (12.5), this returns TRUE
on WIN (7U64), this returns FALSE

Regardless of the bool's value, it should be identical for both OS.

We encountered this on multiple OSX and Windows systems.


// WORK AROUND
// promotion can be controlled by specifying float
{
    float high = 2.0F;
    int   L    = 100;
    return (nHigh / L >= 0.02F);    // 0.02 is of type System.Double
}

on OSX (12.5), this returns TRUE
on WIN (7U64), this returns TRUE
Comment 1 dnbeveridge 2017-07-11 19:40:58 UTC
typo in code "nHigh" => "high" above, thus:

{
    float high = 2.0F;
    int   L    = 100;
    return (high / L >= 0.02);    // 0.02 is of type System.Double
}
Comment 2 Zoltan Varga 2017-07-15 06:08:23 UTC
You can run with -O=float32 to make mono behave more like ms.net wrt floating point arithmetic.
Without it, we expand floats to doubles so calculations are done with more precision.
Comment 3 dnbeveridge 2017-07-19 01:04:49 UTC
Understood.

Just so you know, the default behaviour being different causes many disparities when comparing our machine-learning results across several platforms . . . 

i.e., typically, consistency is usually more important than precision (especially for default behaviours)

Thanks for the response!