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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 16 additions & 18 deletions datafusion/common/src/scalar/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,26 @@

// Constants defined for scalar construction.

// PI ~ 3.1415927 in f32
#[allow(clippy::approx_constant)]
pub(super) const PI_UPPER_F32: f32 = 3.141593_f32;
// Next f32 value above π (upper bound)
pub(super) const PI_UPPER_F32: f32 = std::f32::consts::PI.next_up();

// PI ~ 3.141592653589793 in f64
pub(super) const PI_UPPER_F64: f64 = 3.141592653589794_f64;
// Next f64 value above π (upper bound)
pub(super) const PI_UPPER_F64: f64 = std::f64::consts::PI.next_up();

// -PI ~ -3.1415927 in f32
#[allow(clippy::approx_constant)]
pub(super) const NEGATIVE_PI_LOWER_F32: f32 = -3.141593_f32;
// Next f32 value below -π (lower bound)
pub(super) const NEGATIVE_PI_LOWER_F32: f32 = (-std::f32::consts::PI).next_down();

// -PI ~ -3.141592653589793 in f64
pub(super) const NEGATIVE_PI_LOWER_F64: f64 = -3.141592653589794_f64;
// Next f64 value below -π (lower bound)
pub(super) const NEGATIVE_PI_LOWER_F64: f64 = (-std::f64::consts::PI).next_down();

// PI / 2 ~ 1.5707964 in f32
pub(super) const FRAC_PI_2_UPPER_F32: f32 = 1.5707965_f32;
// Next f32 value above π/2 (upper bound)
pub(super) const FRAC_PI_2_UPPER_F32: f32 = std::f32::consts::FRAC_PI_2.next_up();

// PI / 2 ~ 1.5707963267948966 in f64
pub(super) const FRAC_PI_2_UPPER_F64: f64 = 1.5707963267948967_f64;
// Next f64 value above π/2 (upper bound)
pub(super) const FRAC_PI_2_UPPER_F64: f64 = std::f64::consts::FRAC_PI_2.next_up();

// -PI / 2 ~ -1.5707964 in f32
pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F32: f32 = -1.5707965_f32;
// Next f32 value below -π/2 (lower bound)
pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F32: f32 = (-std::f32::consts::FRAC_PI_2).next_down();

// -PI / 2 ~ -1.5707963267948966 in f64
pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F64: f64 = -1.5707963267948967_f64;
// Next f64 value below -π/2 (lower bound)
pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F64: f64 = (-std::f64::consts::FRAC_PI_2).next_down();
2 changes: 0 additions & 2 deletions datafusion/common/src/scalar/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1186,8 +1186,6 @@ impl ScalarValue {

/// Returns a [`ScalarValue`] representing PI's upper bound
pub fn new_pi_upper(datatype: &DataType) -> Result<ScalarValue> {
// TODO: replace the constants with next_up/next_down when
// they are stabilized: https://doc.rust-lang.org/std/primitive.f64.html#method.next_up
match datatype {
DataType::Float32 => Ok(ScalarValue::from(consts::PI_UPPER_F32)),
DataType::Float64 => Ok(ScalarValue::from(consts::PI_UPPER_F64)),
Expand Down
Loading