/// Coercion rule for numerical types: The type that both lhs and rhs
/// can be casted to for numerical calculation, while maintaining
/// maximum precision
Coercion rule for numerical types: The type that both lhs and rhs
can be casted to for numerical calculation, while maintaining
maximum precision
Coercion rule for numerical types : The type that both lhs and rhs can be casted to for numerical calculation while maintaining maximum precision
pub fn numerical_coercion(lhs_type: &DataType, rhs_type: &DataType) -> Result<DataType> {
    let has_float = is_floating(lhs_type) || is_floating(rhs_type);
    let has_integer = is_integer(lhs_type) || is_integer(rhs_type);
    let has_signed = is_signed_numeric(lhs_type) || is_signed_numeric(rhs_type);
    let has_unsigned = !is_signed_numeric(lhs_type) || !is_signed_numeric(rhs_type);
    let size_of_lhs = numeric_byte_size(lhs_type)?;
    let size_of_rhs = numeric_byte_size(rhs_type)?;
    let max_size_of_unsigned_integer = cmp::max(
        if is_signed_numeric(lhs_type) {
            0
        } else {
            size_of_lhs
        },
        if is_signed_numeric(rhs_type) {
            0
        } else {
            size_of_rhs
        },
    );
    let max_size_of_signed_integer = cmp::max(
        if !is_signed_numeric(lhs_type) {
            0
        } else {
            size_of_lhs
        },
        if !is_signed_numeric(rhs_type) {
            0
        } else {
            size_of_rhs
        },
    );
    let max_size_of_integer = cmp::max(
        if !is_integer(lhs_type) {
            0
        } else {
            size_of_lhs
        },
        if !is_integer(rhs_type) {
            0
        } else {
            size_of_rhs
        },
    );
    let max_size_of_float = cmp::max(
        if !is_floating(lhs_type) {
            0
        } else {
            size_of_lhs
        },
        if !is_floating(rhs_type) {
            0
        } else {
            size_of_rhs
        },
    );
    let should_double = (has_float && has_integer && max_size_of_integer >= max_size_of_float)
        || (has_signed
            && has_unsigned
            && max_size_of_unsigned_integer >= max_size_of_signed_integer);
    construct_numeric_type(
        has_signed,
        has_float,
        if should_double {
            cmp::max(size_of_rhs, size_of_lhs) * 2
        } else {
            cmp::max(size_of_rhs, size_of_lhs)
        },
    )
}
pub fn numerical_coercion ( lhs_type : & DataType , rhs_type : & DataType ) -> Result < DataType > { let has_float = is_floating ( lhs_type ) || is_floating ( rhs_type ) ; let has_integer = is_integer ( lhs_type ) || is_integer ( rhs_type ) ; let has_signed = is_signed_numeric ( lhs_type ) || is_signed_numeric ( rhs_type ) ; let has_unsigned = ! is_signed_numeric ( lhs_type ) || ! is_signed_numeric ( rhs_type ) ; let size_of_lhs = numeric_byte_size ( lhs_type ) ? ; let size_of_rhs = numeric_byte_size ( rhs_type ) ? ; let max_size_of_unsigned_integer = cmp :: max ( if is_signed_numeric ( lhs_type ) { 0 } else { size_of_lhs } , if is_signed_numeric ( rhs_type ) { 0 } else { size_of_rhs } , ) ; let max_size_of_signed_integer = cmp :: max ( if ! is_signed_numeric ( lhs_type ) { 0 } else { size_of_lhs } , if ! is_signed_numeric ( rhs_type ) { 0 } else { size_of_rhs } , ) ; let max_size_of_integer = cmp :: max ( if ! is_integer ( lhs_type ) { 0 } else { size_of_lhs } , if ! is_integer ( rhs_type ) { 0 } else { size_of_rhs } , ) ; let max_size_of_float = cmp :: max ( if ! is_floating ( lhs_type ) { 0 } else { size_of_lhs } , if ! is_floating ( rhs_type ) { 0 } else { size_of_rhs } , ) ; let should_double = ( has_float && has_integer && max_size_of_integer >= max_size_of_float ) || ( has_signed && has_unsigned && max_size_of_unsigned_integer >= max_size_of_signed_integer ) ; construct_numeric_type ( has_signed , has_float , if should_double { cmp :: max ( size_of_rhs , size_of_lhs ) * 2 } else { cmp :: max ( size_of_rhs , size_of_lhs ) } , ) }
Coercion rule for numerical types: The type that both lhs and rhs
can be casted to for numerical calculation, while maintaining
maximum precision
Coercion rule for numerical types : The type that both lhs and rhs can be casted to for numerical calculation while maintaining maximum precision
lhs_type
&DataType
rhs_type
&DataType