real: implement std::iter::Sum

This commit is contained in:
2022-08-21 20:46:43 -07:00
parent 527e2746ed
commit 29e78c74fe

View File

@@ -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<T: Real> Div for Finite<T> {
}
}
#[cfg(feature = "iter")]
impl<T: Real> std::iter::Sum for Finite<T> {
fn sum<I>(iter: I) -> Self
where
I: Iterator<Item = Self>
{
iter.fold(Self::zero(), |a, b| a + b)
}
}
impl<T: ToFloat> ToFloat for Finite<T> {
fn to_f32(&self) -> f32 {