Skip to main content

polars_utils/
algebraic_ops.rs

1#[inline(always)]
2pub fn alg_add_f64(a: f64, b: f64) -> f64 {
3    #[cfg(feature = "nightly")]
4    {
5        a.algebraic_add(b)
6    }
7    #[cfg(not(feature = "nightly"))]
8    {
9        a + b
10    }
11}
12
13#[inline(always)]
14pub fn alg_mul_f64(a: f64, b: f64) -> f64 {
15    #[cfg(feature = "nightly")]
16    {
17        a.algebraic_mul(b)
18    }
19    #[cfg(not(feature = "nightly"))]
20    {
21        a * b
22    }
23}
24
25pub fn alg_sum_f64(it: impl IntoIterator<Item = f64>) -> f64 {
26    // Negative zero is identity element of floating point addition, not
27    // positive zero (since -0.0 + 0.0 = 0.0).
28    it.into_iter().fold(-0.0, alg_add_f64)
29}