From 29e78c74feced48ed351580e5a94376659fdec88 Mon Sep 17 00:00:00 2001 From: colin Date: Sun, 21 Aug 2022 20:46:43 -0700 Subject: [PATCH] real: implement std::iter::Sum --- crates/cross/src/real.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/cross/src/real.rs b/crates/cross/src/real.rs index 62ad7e0..224cc57 100644 --- a/crates/cross/src/real.rs +++ b/crates/cross/src/real.rs @@ -18,6 +18,12 @@ pub trait ToFloat { fn to_f64(&self) -> f64 { self.to_f32() as _ } + fn to_r32(&self) -> R32 { + R32::new(self.to_f32()) + } + fn to_r64(&self) -> R64 { + R64::new(self.to_f64()) + } } @@ -383,6 +389,16 @@ impl Div for Finite { } } +#[cfg(feature = "iter")] +impl std::iter::Sum for Finite { + fn sum(iter: I) -> Self + where + I: Iterator + { + iter.fold(Self::zero(), |a, b| a + b) + } +} + impl ToFloat for Finite { fn to_f32(&self) -> f32 {