Skip to content

Replace π-related bound constants with next_up/next_down #16823

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

rthummaluru
Copy link

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.

- 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"
@github-actions github-actions bot added the common Related to common crate label Jul 18, 2025
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thanks @rthummaluru -- once this this PR passes CI tests it looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Related to common crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Replace π-related bound constants with next_up / next_down
2 participants