From 5871c0b4397a15c46c145918040b9053cc2577e5 Mon Sep 17 00:00:00 2001 From: Ronit Thummaluru <120275888+rthummaluru@users.noreply.github.com> Date: Fri, 18 Jul 2025 17:04:51 -0400 Subject: [PATCH 1/2] =?UTF-8?q?Replace=20=CF=80-related=20bound=20constant?= =?UTF-8?q?s=20with=20next=5Fup/next=5Fdown?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 #16712" --- datafusion/common/src/scalar/consts.rs | 34 ++++++++++++-------------- datafusion/common/src/scalar/mod.rs | 2 -- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/datafusion/common/src/scalar/consts.rs b/datafusion/common/src/scalar/consts.rs index efcde651841b..77b75f15bf46 100644 --- a/datafusion/common/src/scalar/consts.rs +++ b/datafusion/common/src/scalar/consts.rs @@ -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(); \ No newline at end of file diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rs index 8bfcc8f76e69..60d48800d314 100644 --- a/datafusion/common/src/scalar/mod.rs +++ b/datafusion/common/src/scalar/mod.rs @@ -1190,8 +1190,6 @@ impl ScalarValue { /// Returns a [`ScalarValue`] representing PI's upper bound pub fn new_pi_upper(datatype: &DataType) -> Result { - // 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)), From 5ac9d0a17413c920829a1284c0917ac0f1f621cd Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 22 Aug 2025 15:10:14 -0400 Subject: [PATCH 2/2] fmt --- datafusion/common/src/scalar/consts.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/datafusion/common/src/scalar/consts.rs b/datafusion/common/src/scalar/consts.rs index 77b75f15bf46..8cb446b1c921 100644 --- a/datafusion/common/src/scalar/consts.rs +++ b/datafusion/common/src/scalar/consts.rs @@ -26,7 +26,7 @@ pub(super) const PI_UPPER_F64: f64 = std::f64::consts::PI.next_up(); // Next f32 value below -π (lower bound) pub(super) const NEGATIVE_PI_LOWER_F32: f32 = (-std::f32::consts::PI).next_down(); -// Next f64 value below -π (lower bound) +// Next f64 value below -π (lower bound) pub(super) const NEGATIVE_PI_LOWER_F64: f64 = (-std::f64::consts::PI).next_down(); // Next f32 value above π/2 (upper bound) @@ -36,7 +36,9 @@ pub(super) const FRAC_PI_2_UPPER_F32: f32 = std::f32::consts::FRAC_PI_2.next_up( pub(super) const FRAC_PI_2_UPPER_F64: f64 = std::f64::consts::FRAC_PI_2.next_up(); // 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(); +pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F32: f32 = + (-std::f32::consts::FRAC_PI_2).next_down(); // 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(); \ No newline at end of file +pub(super) const NEGATIVE_FRAC_PI_2_LOWER_F64: f64 = + (-std::f64::consts::FRAC_PI_2).next_down();