Struct KahanSum

Source
pub struct KahanSum<T: Float> { /* private fields */ }

Implementations§

Source§

impl<T: Float> KahanSum<T>

Represents an ongoing Kahan summation. New terms can be added to the sum by simple addition.

§Examples

let mut kahan_sum = KahanSum::new();
kahan_sum += 10000.0f32;
kahan_sum += 3.14159f32;
assert_eq!(10003.142f32, kahan_sum.sum());
assert_eq!(0.000011444092f32, kahan_sum.err());
Source

pub fn new() -> Self

Creates a new KahanSum with sum and err initialized to 0

Source

pub fn new_with_value(initial: T) -> Self

Creates a new KahanSum with starting sum set to initial, but err initalized to 0

Source

pub fn sum(&self) -> T

Returns the current running sum

Source

pub fn err(&self) -> T

Returns the current error value

Trait Implementations§

Source§

impl<T: Float> Add<&KahanSum<T>> for KahanSum<T>

Source§

type Output = KahanSum<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: &KahanSum<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Float> Add<T> for KahanSum<T>

Source§

type Output = KahanSum<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: T) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Float> Add for KahanSum<T>

Source§

type Output = KahanSum<T>

The resulting type after applying the + operator.
Source§

fn add(self, rhs: KahanSum<T>) -> Self::Output

Performs the + operation. Read more
Source§

impl<T: Float> AddAssign<&KahanSum<T>> for KahanSum<T>

Source§

fn add_assign(&mut self, rhs: &KahanSum<T>)

Performs the += operation. Read more
Source§

impl<T: Float> AddAssign<T> for KahanSum<T>

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T: Float> AddAssign for KahanSum<T>

Source§

fn add_assign(&mut self, rhs: KahanSum<T>)

Performs the += operation. Read more
Source§

impl<T: Clone + Float> Clone for KahanSum<T>

Source§

fn clone(&self) -> KahanSum<T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug + Float> Debug for KahanSum<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Float> Default for KahanSum<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for KahanSum<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for KahanSum<T>
where T: RefUnwindSafe,

§

impl<T> Send for KahanSum<T>
where T: Send,

§

impl<T> Sync for KahanSum<T>
where T: Sync,

§

impl<T> Unpin for KahanSum<T>
where T: Unpin,

§

impl<T> UnwindSafe for KahanSum<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.