real: implement std::iter::Sum
This commit is contained in:
@@ -18,6 +18,12 @@ pub trait ToFloat {
|
|||||||
fn to_f64(&self) -> f64 {
|
fn to_f64(&self) -> f64 {
|
||||||
self.to_f32() as _
|
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> {
|
impl<T: ToFloat> ToFloat for Finite<T> {
|
||||||
fn to_f32(&self) -> f32 {
|
fn to_f32(&self) -> f32 {
|
||||||
|
Reference in New Issue
Block a user