Repository: risingwavelabs/risingwave
File: src/expr/impl/src/scalar/arithmetic_op.rs (Rust)

Code before:
/// ----
/// 1.791759469228055
///
/// query R
/// SELECT lgamma('5'::float8);
/// ----
/// 3.1780538303479458
///
/// statement error overflow
/// SELECT lgamma('-1'::float8);
///
/// query R
/// SELECT lgamma('-1000.5'::float8);
/// ----
/// -5914.437701116853
///
/// statement error overflow
/// SELECT gamma('0'::float8);
///
/// query R
/// SELECT lgamma('1000'::float8);
/// ----
/// 5905.220423209181
///
/// statement error overflow
/// SELECT gamma('1e308'::float8);
/// ```
#[function("lgamma(float8) -> float8")]
pub fn lgamma_f64(input: F64) -> Result<F64> {
    let (result, _sign) = input.ln_gamma();
    if result.is_infinite() && input.is_finite() {
        return Err(ExprError::NumericOverflow);
    }
    Ok(F64::from(result))
}

#[cfg(test)]
mod tests {
    use std::str::FromStr;

    use num_traits::Float;
    use risingwave_common::types::test_utils::IntervalTestExt;
    use risingwave_common::types::{F32, Int256, Int256Ref, Scalar};

    use super::*;

    #[test]
    fn test() {
        assert_eq!(
            general_add::<_, _, Decimal>(Decimal::from_str("1").unwrap(), 1i32).unwrap(),
            Decimal::from_str("2").unwrap()

Review comment (suggestion):
These test comments reference 'gamma' but are placed in the lgamma function documentation. Line 574 should say "SELECT lgamma('0'::float8);" and line 582 should say "SELECT lgamma('1e308'::float8);".

Code after:
        );
        assert_eq!(sqrt_f64(F64::from(25.00)).unwrap(), F64::from(5.0));
        assert_eq!(
            sqrt_f64(F64::from(107)).unwrap(),
            F64::from(10.344080432788601)
        );
        assert_eq!(
            sqrt_f64(F64::from(12.234567)).unwrap(),
            F64::from(3.4977945908815173)
        );
        assert!(sqrt_f64(F64::from(-25.00)).is_err());
        // sqrt edge cases.
        assert_eq!(sqrt_f64(F64::from(f64::NAN)).unwrap(), F64::from(f64::NAN));
        assert_eq!(
            sqrt_f64(F64::from(f64::neg_zero())).unwrap(),
            F64::from(f64::neg_zero())
        );
        assert_eq!(
            sqrt_f64(F64::from(f64::INFINITY)).unwrap(),
            F64::from(f64::INFINITY)
        );
        assert!(sqrt_f64(F64::from(f64::NEG_INFINITY)).is_err());
        assert_eq!(sqrt_decimal(dec("25.0")).unwrap(), dec("5.0"));
        assert_eq!(
            sqrt_decimal(dec("107")).unwrap(),
            dec("10.344080432788600469738599442")
        );
        assert_eq!(
            sqrt_decimal(dec("12.234567")).unwrap(),
            dec("3.4977945908815171589625746860")
        );
        assert!(sqrt_decimal(dec("-25.0")).is_err());
        assert_eq!(sqrt_decimal(dec("nan")).unwrap(), dec("nan"));
        assert_eq!(sqrt_decimal(dec("inf")).unwrap(), dec("inf"));
        assert_eq!(sqrt_decimal(dec("-0")).unwrap(), dec("-0"));
        assert!(sqrt_decimal(dec("-inf")).is_err());
    }

    #[test]
    fn test_arithmetic_int256() {
        let tuples = vec![
            (0, 1, "0"),
            (0, -1, "0"),
            (1, 1, "1"),
            (1, -1, "-1"),
            (1, 2, "0.5"),
            (1, -2, "-0.5"),
            (9007199254740991i64, 2, "4503599627370495.5"),
        ];

        for (i, j, k) in tuples {