This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new cf3b456727 Replace π-related bound constants with next_up/next_down 
(#16823)
cf3b456727 is described below

commit cf3b45672746f130d68111fe74bf8556bce3e45f
Author: Ronit Thummaluru <[email protected]>
AuthorDate: Fri Aug 22 16:03:19 2025 -0400

    Replace π-related bound constants with next_up/next_down (#16823)
    
    * Replace π-related bound constants with next_up/next_down
    
    - 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"
    
    * fmt
    
    ---------
    
    Co-authored-by: Andrew Lamb <[email protected]>
---
 datafusion/common/src/scalar/consts.rs | 36 +++++++++++++++++-----------------
 datafusion/common/src/scalar/mod.rs    |  2 --
 2 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/datafusion/common/src/scalar/consts.rs 
b/datafusion/common/src/scalar/consts.rs
index efcde65184..8cb446b1c9 100644
--- a/datafusion/common/src/scalar/consts.rs
+++ b/datafusion/common/src/scalar/consts.rs
@@ -17,28 +17,28 @@
 
 // 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();
diff --git a/datafusion/common/src/scalar/mod.rs 
b/datafusion/common/src/scalar/mod.rs
index 51247612e9..f1b6b8385e 100644
--- a/datafusion/common/src/scalar/mod.rs
+++ b/datafusion/common/src/scalar/mod.rs
@@ -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)),


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to