-
Notifications
You must be signed in to change notification settings - Fork 117
Schubfach #1079
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
base: master
Are you sure you want to change the base?
Schubfach #1079
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1079 +/- ##
============================================
+ Coverage 67.23% 67.93% +0.69%
- Complexity 5484 5608 +124
============================================
Files 159 162 +3
Lines 23025 23281 +256
Branches 4126 4165 +39
============================================
+ Hits 15481 15815 +334
+ Misses 6262 6179 -83
- Partials 1282 1287 +5 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice investigation!
} | ||
if (-3 < e && e <= 0) { | ||
} else if (-3 < e && e <= 0) { | ||
return toChars2(h, m, l, e); | ||
} else { | ||
return toChars3(h, m, l, e); | ||
} | ||
return toChars3(h, m, l, e); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change looks unrelated. If that's true, then I generally recommend avoiding including changes like this because it just increases the size of the diff and distracts the reviewer. Non-functional changes are often good, but they should go in standalone PRs when practical.
In this case though, I think the ways of writing this are up to personal preference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's great to fold the string customizations in so that we don't have to do string inspection and modification in post. We have to tweak the special values to be spec-compliant for Ion though.
case PLUS_INF: return "Infinity"; | ||
case MINUS_INF: return "-Infinity"; | ||
default: return "NaN"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These should be +inf
, -inf
and nan
respectively: https://amazon-ion.github.io/ion-docs/docs/float.html#special-values
case PLUS_INF: return "Infinity"; | ||
case MINUS_INF: return "-Infinity"; | ||
default: return "NaN"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See Ion Floats: Special Values.
case PLUS_INF: return "Infinity"; | |
case MINUS_INF: return "-Infinity"; | |
default: return "NaN"; | |
case PLUS_INF: return "+inf"; | |
case MINUS_INF: return "-inf"; | |
default: return "nan"; |
case PLUS_INF: return app.append("Infinity"); | ||
case MINUS_INF: return app.append("-Infinity"); | ||
default: return app.append("NaN"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above:
case PLUS_INF: return app.append("Infinity"); | |
case MINUS_INF: return app.append("-Infinity"); | |
default: return app.append("NaN"); | |
case PLUS_INF: return "+inf"; | |
case MINUS_INF: return "-inf"; | |
default: return "nan"; |
Overview
This PR adds an implementation of the Schubfach algorithm for efficient and accurate float-to-string conversion in ion-java. The Schubfach algorithm provides performance improvements over traditional approaches while maintaining correctness.
Changes
DoubleToDecimal.java
which implements the core Schubfach algorithm for double valuesMathUtils.java
to provide mathematical functions specifically designed for the Schubfach algorithmBenefits
Double.toString()
method in JDK 21References
License
The implementation maintains the original MIT license from Raffaello Giulietti's reference implementation.