Skip to content

Support scalarvalue APIs for f16 regarding Pi values #19465

@Jefffrey

Description

@Jefffrey

See these four functions:

/// Returns a [`ScalarValue`] representing PI's upper bound
pub 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::Float32 => Ok(ScalarValue::from(consts::PI_UPPER_F32)),
DataType::Float64 => Ok(ScalarValue::from(consts::PI_UPPER_F64)),
_ => {
_internal_err!("PI_UPPER is not supported for data type: {}", datatype)
}
}
}

/// Returns a [`ScalarValue`] representing -PI's lower bound
pub 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::Float32 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F32)),
DataType::Float64 => Ok(ScalarValue::from(consts::NEGATIVE_PI_LOWER_F64)),
_ => {
_internal_err!("-PI_LOWER is not supported for data type: {}", datatype)
}
}
}

/// Returns a [`ScalarValue`] representing FRAC_PI_2's upper bound
pub 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::Float32 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F32)),
DataType::Float64 => Ok(ScalarValue::from(consts::FRAC_PI_2_UPPER_F64)),
_ => {
_internal_err!("PI_UPPER/2 is not supported for data type: {}", datatype)
}
}
}

// Returns a [`ScalarValue`] representing FRAC_PI_2's lower bound
pub 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::Float32 => {
Ok(ScalarValue::from(consts::NEGATIVE_FRAC_PI_2_LOWER_F32))
}
DataType::Float64 => {
Ok(ScalarValue::from(consts::NEGATIVE_FRAC_PI_2_LOWER_F64))
}
_ => {
_internal_err!("-PI/2_LOWER is not supported for data type: {}", datatype)
}
}
}

We should look for a solution that does not involve casting the f32 constant to a f16.

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions