Apache DataFusion SQL Query Engine
Add: PI upper/lower bound f16 constants to ScalarValue (#19497)
xonxed7af0b12a4b
diff --git a/datafusion/common/src/scalar/consts.rs b/datafusion/common/src/scalar/consts.rsindex 8cb446b1c9..599c2523cd 100644--- a/datafusion/common/src/scalar/consts.rs+++ b/datafusion/common/src/scalar/consts.rs@@ -17,24 +17,36 @@// Constants defined for scalar construction.+// Next F16 value above π (upper bound)+pub(super) const PI_UPPER_F16: half::f16 = half::f16::from_bits(0x4249);+// Next f32 value above π (upper bound)pub(super) const PI_UPPER_F32: f32 = std::f32::consts::PI.next_up();// Next f64 value above π (upper bound)pub(super) const PI_UPPER_F64: f64 = std::f64::consts::PI.next_up();+// Next f16 value below -π (lower bound)+pub(super) const NEGATIVE_PI_LOWER_F16: half::f16 = half::f16::from_bits(0xC249);+// 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)pub(super) const NEGATIVE_PI_LOWER_F64: f64 = (-std::f64::consts::PI).next_down();+// Next f16 value above π/2 (upper bound)+pub(super) const FRAC_PI_2_UPPER_F16: half::f16 = half::f16::from_bits(0x3E49);+// Next f32 value above π/2 (upper bound)pub(super) const FRAC_PI_2_UPPER_F32: f32 = std::f32::consts::FRAC_PI_2.next_up();// Next f64 value above π/2 (upper bound)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_F16: half::f16 = half::f16::from_bits(0xBE49);+// 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();diff --git a/datafusion/common/src/scalar/mod.rs b/datafusion/common/src/scalar/mod.rsindex 8b68b29d3c..e4e048ad3c 100644--- a/datafusion/common/src/scalar/mod.rs+++ b/datafusion/common/src/scalar/mod.rs@@ -1342,8 +1342,7 @@ impl ScalarValue {/// Returns a [`ScalarValue`] representing PI's upper boundpub fn new_pi_upper(datatype: &DataType) -> Result<ScalarValue> {match datatype {- // TODO: half::f16 doesn't seem to have equivalent- // https://github.com/apache/datafusion/issues/19465+ DataType::Float16 => Ok(ScalarValue::Float16(Some(consts::PI_UPPER_F16))),DataType::Float32 => Ok(ScalarValue::from(consts::PI_UPPER_F32)),DataType::Float64 => Ok(ScalarValue::from(consts::PI_UPPER_F64)),_ => {@@ -1355,8 +1354,9 @@ impl ScalarValue {/// Returns a [`ScalarValue`] representing -PI's lower boundpub fn new_negative_pi_lower(datatype: &DataType) -> Result<ScalarValue> {match datatype {- // TODO: half::f16 doesn't seem to have equivalent- // https://github.com/apache/datafusion/issues/19465+ DataType::Float16 => {+ Ok(ScalarValue::Float16(Some(consts::NEGATIVE_PI_LOWER_F16)))+ }DataType::Float32 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F32)),DataType::Float64 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F64)),_ => {@@ -1368,8 +1368,9 @@ impl ScalarValue {/// Returns a [`ScalarValue`] representing FRAC_PI_2's upper boundpub fn new_frac_pi_2_upper(datatype: &DataType) -> Result<ScalarValue> {match datatype {- // TODO: half::f16 doesn't seem to have equivalent- // https://github.com/apache/datafusion/issues/19465+ DataType::Float16 => {+ Ok(ScalarValue::Float16(Some(consts::FRAC_PI_2_UPPER_F16)))+ }DataType::Float32 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F32)),DataType::Float64 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F64)),_ => {@@ -1381,8 +1382,9 @@ impl ScalarValue {// Returns a [`ScalarValue`] representing FRAC_PI_2's lower boundpub fn new_neg_frac_pi_2_lower(datatype: &DataType) -> Result<ScalarValue> {match datatype {- // TODO: half::f16 doesn't seem to have equivalent- // https://github.com/apache/datafusion/issues/19465+ DataType::Float16 => Ok(ScalarValue::Float16(Some(+ consts::NEGATIVE_FRAC_PI_2_LOWER_F16,+ ))),DataType::Float32 => {Ok(ScalarValue::from(consts::NEGATIVE_FRAC_PI_2_LOWER_F32))}