Replace π-related bound constants with next_up/next_down #16823
+16
−20
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.