dashu_float/
iter.rs

1//! Implementation of core::iter traits
2
3use crate::{fbig::FBig, repr::Word, round::Round};
4use core::{
5    iter::{Product, Sum},
6    ops::{Add, Mul},
7};
8
9// TODO(v0.5): implement precise summation of multiple floats, however,
10//      this means what only Sum<Self> should be implemented, which requires
11//      narrowing the implementation
12impl<T, R: Round, const B: Word> Sum<T> for FBig<R, B>
13where
14    Self: Add<T, Output = Self>,
15{
16    fn sum<I: Iterator<Item = T>>(iter: I) -> Self {
17        iter.fold(FBig::ZERO, FBig::add)
18    }
19}
20
21impl<T, R: Round, const B: Word> Product<T> for FBig<R, B>
22where
23    Self: Mul<T, Output = Self>,
24{
25    fn product<I: Iterator<Item = T>>(iter: I) -> Self {
26        iter.fold(FBig::ONE, FBig::mul)
27    }
28}