Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

BigInteger Log10 can produce incorrect result

Open Beginner friendly
#134,654 1 comment 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
88/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
backend

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

area-System.Numerics untriaged
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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/runtime

All issues in dotnet/runtime

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.