BigInteger Log10 can produce incorrect result
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
Research direction
Start at the BigInteger.cs location linked in the issue and reproduce the generic and direct BigInteger.Log10 calls with BigInteger.Pow(10, 21306). Inspect the coefficient used for the estimate and verify that the generic call returns 21306 without changing the direct call's correct result.
Written by the indexing model from the issue text.
Description
Description
BigInteger BigInteger.Log10 can produce an incorrect result for the IBinaryInteger<T> implementation. The coefficient 1292913986 / 2^32 is slightly below log10(2), so the estimate can be too small.
Reproduction Steps
using System;
using System.Numerics;
static T IntegerLog10<T>(T value) where T : IBinaryInteger<T> => T.Log10(value);
Console.WriteLine(IntegerLog10(BigInteger.Pow(10, 21306))); // Incorrect, prints 21305
Console.WriteLine(BigInteger.Log10(BigInteger.Pow(10, 21306))); // Correct, prints 21306
Expected behavior
Both should print 21306.
Actual behavior
The first invocation prints 21305, the second line is 21306.
Regression?
No, this API is new in .NET 11.
Known Workarounds
No response
Configuration
.NET SDK:
Version: 11.0.100-rc.1.26425.128
Commit: 3551975be0
Workload version: 11.0.100-manifests.a6e318ce
MSBuild version: 18.11.0-1.26425.128+3551975be
Runtime Environment:
OS Name: Mac OS X
OS Version: 27.0
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/11.0.100-rc.1.26425.128
Other information
This appears to be off-by-one. https://github.com/dotnet/runtime/blob/0598ca0a45c1f29be94f889a1fc6e9b30c40ea64/src/libraries/System.Runtime.Numerics/src/System/Numerics/BigInteger.cs#L3958
it should probably be 1292913987L not 1292913986L.
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- Avg merge
- 2d 20h
- Merged PRs (30d)
- 614
Getting set up
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/runtime
-
area-System.Memory untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#134840 · 4 comments · 1 reaction ·
Maintainers usually reply within 1 day
-
area-System.Linq untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
dotnet/runtime#134736 · 3 comments ·
Maintainers usually reply within 1 day
-
area-System.Numerics.Tensors untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
dotnet/runtime#134691 · 2 comments ·
Maintainers usually reply within 1 day
-
area-System.Threading blocking-clean-ci Known Build Error untriaged
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
dotnet/runtime#134679 · 4 comments ·
Maintainers usually reply within 1 day
-
ARM64: conditional compare rejects negative immediates the emitter can already encode as `ccmn`Openarea-CodeGen-coreclr performance
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
dotnet/runtime#134663 · 1 comment ·
Maintainers usually reply within 1 day
Similar issues
-
go 🏃 testing 🧪
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
valkey-io/valkey-glide#7239 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
SubtitleEdit/subtitleedit#15462 ·
Maintainers usually reply within 1 day
-
:watch: Not Triaged
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
comp:instrumentation.aspnetcore
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
open-telemetry/opentelemetry-dotnet-contrib#5427 ·
Maintainers usually reply within 1 day
-
enhancement needs-triage pkg:OpenTelemetry
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
open-telemetry/opentelemetry-dotnet#7851 · 4 comments ·
Maintainers usually reply within 1 day