Replace π-related bound constants with next_up/next_down#16823
Merged
alamb merged 4 commits intoapache:mainfrom Aug 22, 2025
Merged
Replace π-related bound constants with next_up/next_down#16823alamb merged 4 commits intoapache:mainfrom
alamb merged 4 commits intoapache:mainfrom
Conversation
- Replaced 8 hardcoded π constants with std library next_up/next_down methods - All f32 constants remain identical (perfect precision match) - f64 π constants improved by ~4.4e-16 (better mathematical precision) - Removed clippy::approx_constant allows (no longer needed) - Updated comments to explain bounds purpose and method - Removed obsolete TODO comment about next_up/next_down stabilization Closes apache#16712"
alamb
approved these changes
Jul 19, 2025
Contributor
alamb
left a comment
There was a problem hiding this comment.
Thanks @rthummaluru -- once this this PR passes CI tests it looks good to me
findepi
approved these changes
Jul 22, 2025
Member
|
Current MSRV is 1.85.1. We need to wait until MSRV=1.86. |
Contributor
|
MSRV was updated by @adriangb in I merged up from main and kicked off tests again |
adriangb
approved these changes
Aug 22, 2025
Contributor
|
I think this one is good to go -- it has been waiting until we could use the new rust features |
Contributor
|
Thanks everyone |
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.
Which issue does this PR close?
Closes #16712.
Rationale for this change
Rust 1.86 stabilized f64::next_up() and f32::next_up() methods, along with their next_down() counterparts. These methods provide IEEE 754 compliant ways to get the next representable floating-point value, which is more precise and maintainable than manually calculated hardcoded constants.
The existing hardcoded π-related constants were close approximations, but using the standard library methods ensures mathematical correctness and improves code clarity.
What changes are included in this PR?
Replaced 8 hardcoded π-related floating-point constants with next_up()/next_down() calls
Removed #[allow(clippy::approx_constant)] attributes (no longer needed)
Updated comments to explain the purpose (bounds) and method (next_up/next_down)
Removed obsolete TODO comment about next_up/next_down stabilization
Constants updated:
PI_UPPER_F32/F64 → std::f32/f64::consts::PI.next_up()
NEGATIVE_PI_LOWER_F32/F64 → (-std::f32/f64::consts::PI).next_down()
FRAC_PI_2_UPPER_F32/F64 → std::f32/f64::consts::FRAC_PI_2.next_up()
NEGATIVE_FRAC_PI_2_LOWER_F32/F64 → (-std::f32/f64::consts::FRAC_PI_2).next_down()
Value Analysis:
All f32 constants remain identical (perfect precision match)
f64 π constants show minor precision improvements (~4.4e-16)
f64 π/2 constants remain identical
Are these changes tested?
Yes, these changes are tested by existing tests. The constants are used in mathematical functions throughout DataFusion, and all existing tests continue to pass, confirming compatibility.