Repository navigation
Use Schubfach algorithm for float repr - #2128
Merged
Merged
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The upstream MIT notice is missing from the ports and binary packages, and the non-NET formatting implementations lack independent boundary-value coverage.
2 open issues
What changed in this PR
Replaces float representation formatting with a Schubfach implementation to produce shortest round-tripping strings across supported runtimes, addressing the excess digits reported in #1626.
Changes:
- Adds the converter and a source generator for its power-of-ten lookup table.
- Routes float representations through Schubfach and reports
"short"representation style on all targets. - Updates formatting, array and pickle expectations, and enables additional float tests on .NET Core.
| File | Description |
|---|---|
| tests/suite/test_formatting.py | Removes legacy float representation expected failures. |
| tests/suite/stdlib/test_float.py | Enables two float tests on .NET Core. |
| tests/suite/modules/type_related/test_array.py | Uses shortest float representations in array expectations. |
| tests/suite/modules/io_related/test_cPickle.py | Updates selection of legacy pickle expectations. |
| src/roslyn/IronPython.SourceGenerator/SchubfachGenerator.cs | Generates power-of-ten significands. |
| src/roslyn/IronPython.SourceGenerator/IronPython.SourceGenerator.csproj | Defines the source-generator project. |
| src/roslyn/IronPython.Analyzer/IronPython.Analyzer.csproj | Marks the analyzer as a Roslyn component. |
| src/core/IronPython/Runtime/Schubfach.cs | Implements conversion and Python-style formatting. |
| src/core/IronPython/Runtime/Operations/FloatOps.cs | Delegates float representation to Schubfach. |
| src/core/IronPython/Modules/sys.cs | Reports short float representation style universally. |
| src/core/IronPython/IronPython.csproj | References the source generator as an analyzer. |
| IronPython.slnx | Adds the source-generator project to the solution. |
Review effort: Balanced
Comment on lines
+3
to
+5
| // Copyright (c) 2025 Victor Zverovich | ||
| // Distributed under the MIT license. | ||
| // Ported from schubfach.cc of https://github.com/vitaut/schubfach. |
Contributor
Author
There was a problem hiding this comment.
Licensing is a general issue which probably warrants its own PR...
Member
|
Testing Copilot… 😃 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Use the Schubfach algorithm for float repr, ported from https://github.com/vitaut/schubfach. This now gives the shortest round-tripping string, matching CPython. I opted to use this across the board (including for .NET since it's faster and .NET 10 has a bug with its "R" formatting).
Resolves #1626