Bug 28571 - Incorrect behavior in System.Numerics.BigInteger(Single v) Constructor
Summary: Incorrect behavior in System.Numerics.BigInteger(Single v) Constructor
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.10.0
Hardware: PC Windows
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2015-03-31 00:22 UTC by nader
Modified: 2015-03-31 10:19 UTC (History)
3 users (show)

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:

Description nader 2015-03-31 00:22:43 UTC
When constructing an object of BigInteger using BigInteger(Single)/BigInteger(Double) using floating point numbers between (0,1), The documentation specifies (https://msdn.microsoft.com/en-us/library/dd268360%28v=vs.110%29.aspx) that the fractional part of the parameter has to get truncated. This doesn't appear to be the case in Xamarin Android and mono 3.3.0. This can be checked by reading the Sign and IsZero properties in the resulting BigInteger object.  

To reproduce, run the following code snippet:

System.Single v1 = (System.Single)0.001;
System.Numerics.BigInteger v2 =  new System.Numerics.BigInteger(v1);
Boolean z = v5.IsZero;
int sign = v5.Sign;

Expected result:
z = true
sign = 0

Observed result:
z = false
sign = 1

The code snippet above was ran using Xamarin Android and Windows Phone 8.1. The
same issue happens when running the code in .Net 4.5 and  mono 3.3.0.

It should be noted that the Windows Phone 8.1 and .Net 4.5 output the expected result.

Additional Build Environment info:
Xamarin.Android Version: 4.16.0 (Business Edition)
Java SDK: C:\Program Files (x86)\Java\jdk1.6.0_39
Comment 1 Marek Safar 2015-03-31 10:19:30 UTC
Already fixed in Mono 4.0