-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversions from BigInteger to Double are not always as precise as from Long #49611
Comments
Tagging subscribers to this area: @tannergooding, @pgovind Issue DetailsDescriptionThe gist of the issue is that some precision is apparently lost when using the explicit conversion operator BigInteger a = long.MaxValue / 2;
Console.WriteLine($"Source: {a}");
Console.WriteLine($"BigInt: {(double)a:F0}");
Console.WriteLine($"Long: {(double)(long)a:F0}"); This will print:
ConfigurationTested with the latest bits from Regression?Not a regression - the reproduction works on
|
This looks like a rounding bug. Putting into 6.0 so we can do an investigation to determine if this is a simple fix or not. |
@tannergooding , currently I trying to fix this bug, but I have little question linked with RunSingleExplicitCastFromBigIntegerTests. Can you explain me this lines of test:
This lines makes next:
Is it normall? I think, it should return false but I'm not sure. |
Yes. IEEE 754 binary floating-point numbers are non-exact and have a sliding epsilon (delta/difference) between values. This epsilon starts at
|
Description
The gist of the issue is that some precision is apparently lost when using the explicit conversion operator
operator double(BigInteger integer)
, as compared to a direct cast fromlong
. Here's a very simple reproduction:This will print:
Configuration
Tested with the latest bits from
dotnet/installer
-6.0.100-preview.3.21164.5
on Windows 10 x64. I do not believe this is an architecture-specific issue as all the code that does it is fully managed and uses simple arithmetic.Regression?
Not a regression - the reproduction works on
net6.0
,net5.0
andnetcoreapp3.1
. It appears that the code responsible for the conversion hasn't been touched in a long time.The text was updated successfully, but these errors were encountered: