Skip to content

Add polyfill for Math.Log2(double) - #136

Merged
Tyrrrz merged 3 commits into
primefrom
copilot/add-polyfill-for-log2
Aug 2, 2026
Merged

Add polyfill for Math.Log2(double)#136
Tyrrrz merged 3 commits into
primefrom
copilot/add-polyfill-for-log2

Conversation

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Math.Log2(double) was introduced in .NET Core 3.0 / .NET Standard 2.1 and had no polyfill for earlier targets.

Polyfill

  • Added PolyShim/NetCore30/Math.cs with a static extension implementing Math.Log2(double) as Math.Log(x, 2), guarded to only apply on .NET Framework, pre-.NET Core 3.0, and pre-netstandard2.1 targets.
Math.Log2(8.0); // 3.0

Tests

  • Added PolyShim.Tests/NetCore30/MathTests.cs covering typical values and edge cases (0, +Infinity, negative input, NaN).

Docs

  • Regenerated Signatures.md to include the new member.

@Tyrrrz
Tyrrrz marked this pull request as ready for review August 2, 2026 20:28
Copilot AI review requested due to automatic review settings August 2, 2026 20:28
@codecov

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.17%. Comparing base (527ee10) to head (0085351).

Additional details and impacted files
@@           Coverage Diff           @@
##            prime     #136   +/-   ##
=======================================
  Coverage   99.17%   99.17%           
=======================================
  Files         149      150    +1     
  Lines        3998     4005    +7     
  Branches       88       88           
=======================================
+ Hits         3965     3972    +7     
  Misses         13       13           
  Partials       20       20           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request adds a PolyShim polyfill for System.Math.Log2(double) for targets that predate .NET Core 3.0 / .NET Standard 2.1, along with tests and signature documentation updates.

Changes:

  • Added a NetCore30 polyfill for Math.Log2(double) implemented via an extension member.
  • Added NetCore30 tests covering standard and edge-case inputs for Log2.
  • Regenerated Signatures.md to include the new member and updated totals.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
Signatures.md Updates signature inventory totals and lists Math.Log2(double) as a .NET Core 3.0 member.
PolyShim/NetCore30/Math.cs Introduces the Math.Log2(double) polyfill under appropriate target guards.
PolyShim.Tests/NetCore30/MathTests.cs Adds test coverage for Math.Log2(double) including edge cases.
Suppressed comments (1)

PolyShim.Tests/NetCore30/MathTests.cs:18

  • Asserting Be(double.NaN) can be brittle because NaN != NaN under == semantics. To make intent unambiguous and avoid assertion-library edge cases, assert with double.IsNaN(...).
        Math.Log2(-1.0).Should().Be(double.NaN);
        Math.Log2(double.NaN).Should().Be(double.NaN);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread PolyShim/NetCore30/Math.cs
Comment thread PolyShim.Tests/NetCore30/MathTests.cs
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Tyrrrz

Tyrrrz commented Aug 2, 2026

Copy link
Copy Markdown
Owner

@copilot this method was added only in .NET Core 3.0. It's not available in .NET Standard.

Copilot AI commented Aug 2, 2026

Copy link
Copy Markdown
Contributor Author

@copilot this method was added only in .NET Core 3.0. It's not available in .NET Standard.

Fixed in commit Fix #if guard for Math.Log2: applies to all NETSTANDARD targets. Changed the guard from (NETSTANDARD && !NETSTANDARD2_1_OR_GREATER) to (NETSTANDARD) so the polyfill now applies to all .NET Standard targets (1.x, 2.0, and 2.1), since Math.Log2 is not available in any .NET Standard version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants