Coverage for pygeodesy/fsums.py : 97%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
# -*- coding: utf-8 -*-
Set env variable C{PYGEODESY_FSUM_RESIDUAL} to nay non-empty string to throw a L{ResidualError} for division or exponention by an L{Fsum} instance with a non-zero C{residual}, see methoda L{Fsum.fdiv} and L{Fsum.fpow}. ''' # make sure int/int division yields float quotient, see .basics
neg, signOf _TypeError, _ValueError, _xkwds_get, \ _ZeroDivisionError _finite_, _iadd_, _negative_, _not_, \ _PERCENT_, _scalar_, _SLASH_, _SPACE_, \ _STAR_, _supported_, _0_0, _1_0, _N_1_0 # from pygeodesy.props import Property_RO, property_RO
'''(INTERNAL) Half-even rounding. ''' (r < 0 and p < 0): # signs match
'''(INTERNAL) Raise C{TypeError} or C{ValueError} if not scalar or infinite. ''' X, t = _ValueError, _not_(_finite_) except TypeError as x: X, t = _TypeError, str(x) except ValueError as x: X, t = _ValueError, str(x) except Exception as x: X, t = _NotImplementedError, repr(x) if index is not None: n = Fmt.SQUARE(n, index) raise X(n, v, txt=t)
'''(INTERNAL) Yield all items as C{float}s. ''' ps = map(neg, ps) else:
'''(INTERNAL) Return B{C{other}} as an L{Fsum}. '''
'''(INTERNAL) Precision C{2sum} of M{a + b} as 2-tuple (sum, residual). ''' raise _OverflowError(unstr(_2sum.__name__, a, b), txt=str(s))
'''(INTERNAL) Residual as C{str}. '''
'''Error raised for an operation involving an L{Fsum} with a non-zero residual. '''
'''Precision I{running} floating point summation similar to standard Python's C{math.fsum}.
Unlike C{math.fsum}, this class accumulates values and provides intermediate, I{running} precision floating point summation. Accumulation may continue after intermediate, I{running} summations.
@note: Handling of exceptions, C{inf}, C{INF}, C{nan} and C{NAN} values differs from standard Python's C{math.fsum}.
@note: Values to be accumulated are C{scalar} or L{fsum} instances with C{scalar} meaning type C{float}, C{int} or any type convertible to C{float}.
@see: U{Hettinger<https://GitHub.com/ActiveState/code/blob/master/recipes/Python/ 393090_Binary_floating_point_summatiaccurate_full/recipe-393090.py>}, U{Kahan<https://WikiPedia.org/wiki/Kahan_summation_algorithm>}, U{Klein<https://Link.Springer.com/article/10.1007/s00607-005-0139-x>}, Python 2.6+ file I{Modules/mathmodule.c} and the issue log U{Full precision summation<https://Bugs.Python.org/issue2819>}. '''
'''New L{Fsum} for I{running} precision floating point summation.
@arg xs: No, one or more initial values (C{scalar} or L{Fsum} instances). @kwarg name_NN: Optional name (C{str}).
@see: Method L{Fsum.fadd}. ''' # self._n = 0
'''Return this instance' absolute value as an L{Fsum}. '''
'''Return the sum C{B{self} + B{other}} as an L{Fsum}.
@arg other: An L{Fsum} or C{scalar}.
@return: The sum (L{Fsum}).
@see: Method L{Fsum.__iadd__}. '''
'''Return this instance as the integer ratio.
@return: 2-Tuple C{(numerator, denominator)} both C{int} and with C{denominator} positive.
@see: Standard C{float.as_integer_ratio} in Python 3+. ''' if isint(r): # PYCHOK no cover n += int(r) * d else:
'''Return C{True} if this instance is non-zero. '''
'''Return this instance' C{math.ceil} as C{int} or C{float}.
@return: An C{int} in Python 3+, C{float} in Python 2-.
@see: Methods L{Fsum.__floor__} and property L{Fsum.ceil}. '''
'''Return C{divmod(B{self}, B{other})} as 2-tuple C{(quotient, remainder)}, an C{int} in Python 3+ or C{float} in Python 2- and an L{Fsum}.
@arg other: An L{Fsum} or C{scalar} modulus.
@see: Method L{Fsum.__itruediv__}. '''
'''Compare this with an other instance or scalar. '''
'''Return this instance' current precision running sum as C{float}.
@see: Method L{Fsum.fsum} and property L{Fsum.float_int}. '''
'''Return this instance' C{math.floor} as C{int} or C{float}.
@return: An C{int} in Python 3+, C{float} in Python 2-.
@see: Methods L{Fsum.__ceil__} and property L{Fsum.floor}. '''
'''Return C{B{self} // B{other}} as an L{Fsum}.
@arg other: An L{Fsum} or C{scalar} divisor.
@return: The C{floor} quotient (L{Fsum}).
@see: Methods L{Fsum.__ifloordiv__}. '''
def __format__(self, *other): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, *other)
'''Compare this with an other instance or scalar. '''
'''Compare this with an other instance or scalar. '''
def __hash__(self): # PYCHOK no cover '''Return this instance' C{hash}. ''' return hash(self._ps) # XXX id(self)?
'''Apply C{B{self} += B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar}.
@return: This instance, updated (L{Fsum}).
@raise TypeError: Invalid B{C{other}} type.
@see: Method L{Fsum.fadd}. ''' raise self._TypeError(_iadd_, other)
'''Apply C{B{self} //= B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar} divisor.
@return: This instance, updated (L{Fsum}).
@raise ResidualError: Non-zero residual in B{C{other}}.
@raise TypeError: Invalid B{C{other}} type.
@raise ValueError: Invalid or non-finite B{C{other}}.
@raise ZeroDivisionError: Zero B{C{other}}.
@see: Methods L{Fsum.__itruediv__}. '''
def __imatmul__(self, other): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, other)
'''Apply C{B{self} %= B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar} modulus.
@return: This instance, updated (L{Fsum}).
@see: Method L{Fsum.__divmod__}. '''
'''Apply C{B{self} *= B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar} factor.
@return: This instance, updated (L{Fsum}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Invalid B{C{other}} type.
@see: Method L{Fsum.fmul}. ''' else: else: raise self._TypeError(_mul_ + _fset_, other)
'''Return this instance as an C{int}.
@see: Methods L{Fsum.__ceil__} and L{Fsum.__floor__} and properties L{Fsum.ceil}, L{Fsum.floor} and L{Fsum.float_int}. '''
'''Apply C{B{self} **= B{other}} to this instance.
@arg other: The exponent (L{Fsum} or C{scalar}). @arg mod: Optional modulus (C{int} on C{None}) for the 3-argument C{pow(B{self}, B{other}, B{mod})} version.
@return: This instance, updated (L{Fsum}).
@note: If B{C{mod}} is given, the result is an C{int} in Python 3+ if this instance C{is_integer}, in particular when B{C{mod}} given as C{None}.
@raise OverflowError: Partial C{2sum} overflow.
@raise ResidualError: If this instance has a non-zero residual and either B{C{mod}} is given as non-C{None} or B{C{other}} is a negative or fractional C{scalar}.
@raise TypeError: Invalid B{C{other}} type or 3-argument C{pow} invocation failed.
@raise ValueError: If B{C{other}} is a negative C{scalar} and this instance is C{0} or B{C{other}} is a fractional C{scalar} and this instance is negative or has a non-zero residual or B{C{mod}} is given and C{0}.
@see: CPython function U{float_pow<https://GitHub.com/ python/cpython/blob/main/Objects/floatobject.c>}. '''
'''Apply C{B{self} -= B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar}.
@return: This instance, updated (L{Fsum}).
@raise TypeError: Invalid B{C{other}} type.
@see: Method L{Fsum.fadd}. ''' raise self._TypeError(_sub_ + _fset_, other)
'''Return an C{iter}ator over a C{partials} duplicate. '''
'''Apply C{B{self} /= B{other}} to this instance.
@arg other: An L{Fsum} or C{scalar} divisor.
@return: This instance, updated (L{Fsum}).
@raise OverflowError: Partial C{2sum} overflow.
@raise ResidualError: Non-zero residual in B{C{other}}.
@raise TypeError: Invalid B{C{other}} type.
@raise ValueError: Invalid or non-finite B{C{other}}.
@raise ZeroDivisionError: Zero B{C{other}}.
@see: Method L{Fsum.__ifloordiv__}. '''
'''Compare this with an other instance or scalar. '''
'''Return the I{total} number of values accumulated (C{int}). '''
'''Compare this with an other instance or scalar. '''
def __matmul__(self, other): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, other)
'''Return C{B{self} % B{other}} as an L{Fsum}.
@see: Method L{Fsum.__imod__}. '''
'''Return C{B{self} * B{other}} as an L{Fsum}.
@see: Method L{Fsum.__imul__}. '''
'''Compare this with an other instance or scalar. '''
'''Return I{a copy of} this instance, negated. '''
'''Return this instance I{as-is}, like C{float.__pos__()}. '''
'''Return C{B{self}**B{other}} as an L{Fsum}.
@see: Method L{Fsum.__ipow__}. '''
'''Return C{B{other} + B{self}} as an L{Fsum}.
@see: Method L{Fsum.__iadd__}. '''
'''Return C{divmod(B{other}, B{self})} as 2-tuple C{(quotient, remainder)}.
@see: Method L{Fsum.__divmod__}. '''
# def __repr__(self): # '''Return the default C{repr(this)}. # ''' # return self.toRepr()
'''Return C{B{other} // B{self}} as an L{Fsum}.
@see: Method L{Fsum.__ifloordiv__}. '''
def __rmatmul__(self, other): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, other)
'''Return C{B{other} % B{self}} as an L{Fsum}.
@see: Method L{Fsum.__imod__}. '''
'''Return C{B{other} * B{self}} as an L{Fsum}.
@see: Method L{Fsum.__imul__}. '''
def __round__(self, ndigits=None): # PYCHOK no cover '''Not implemented.''' return _NotImplemented(self, ndigits=ndigits)
'''Return C{B{other}**B{self}} as an L{Fsum}.
@see: Method L{Fsum.__ipow__}. ''' else:
'''Return C{B{other} - B{self}} as L{Fsum}.
@see: Method L{Fsum.__isub__}. '''
'''Return C{B{other} / B{self}} as an L{Fsum}.
@see: Method L{Fsum.__itruediv__}. '''
'''Return the size of this instance in C{bytes}. ''' self._fsum2, self._fsum2.fsum, self._fsum2.residual, self._n, self._ps, *self._ps))
'''Return the default C{str(this)}. '''
'''Return C{B{self} - B{other}} as an L{Fsum}.
@arg other: An L{Fsum} or C{scalar}.
@return: The difference (L{Fsum}).
@see: Method L{Fsum.__isub__}. '''
'''Return C{B{self} / B{other}} as an L{Fsum}.
@arg other: An L{Fsum} or C{scalar} divisor.
@return: The quotient (L{Fsum}).
@see: Method L{Fsum.__itruediv__}. '''
if _sys_version_info2 < (3, 0): # PYCHOK no cover # <https://docs.Python.org/2/library/operator.html#mapping-operators-to-functions> __div__ = __truediv__ __idiv__ = __itruediv__ __long__ = __int__ __nonzero__ = __bool__ __rdiv__ = __rtruediv__
'''Get this instance' C{ceil} value (C{int} in Python 3+, C{float} in Python 2-).
@note: The C{ceil} takes the C{residual} into account.
@see: Properties L{Fsum.floor}, L{Fsum.float_int}, L{Fsum.imag} and L{Fsum.real}. '''
'''(INTERNAL) Subtract an B{C{other}} instance or scalar and return an L{Fsum2Tuple}C{(fsum, residual)} for comparison operator B{C{cop}}. ''' else: raise self._TypeError(cop, other) else:
'''(INTERNAL) Make a fast, un-named copy. '''
'''Return C{divmod(B{self}, B{other})} as 2-tuple C{(quotient, remainder)}.
@arg other: An L{Fsum} or C{scalar} divisor.
@return: 2-Tuple C{(quotient, remainder)}, with the C{quotient} an C{int} in Python 3+ or a C{float} in Python 2- and the C{remainder} an L{Fsum} instance.
@see: Method L{Fsum.__itruediv__}. '''
'''(INTERNAL) Format an B{C{Error}} for C{{self} B{op} B{other}}. '''
'''Accumulate more scalar values from an iterable.
@arg xs: Iterable, list, tuple, etc. (C{scalar} or L{Fsum} instances).
@return: This instance (L{Fsum}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value. ''' else: # ... backward compatibility self._fadd_(_2float(xs=xs)) # PYCHOK no cover
'''Accumulate more I{scalar} values from positional arguments.
@arg xs: Values to add (C{scalar} or L{Fsum} instances), all positional.
@return: This instance (L{Fsum}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value. '''
'''(INTERNAL) Accumulate more I{known} C{scalar}s. ''' # assert self._ps is ps
'''(INTERNAL) Add all positional, I{known} C{scalar}s. '''
'''(INTERNAL) Update the C{partials}, by removing and re-adding the final C{partial}. ''' else: # force zap
'''Copy this instance, C{shallow} or B{C{deep}}.
@return: The copy (L{Fsum}). ''' # f._update(other=self)
'''(INTERNAL) C{divmod(B{self}, B{other})} as 2-tuple (C{int} or C{float}, C{self}). ''' # mostly like like CPython function U{float_divmod # <https://GitHub.com/python/cpython/blob/main/Objects/floatobject.c>}, # but at least divmod(-3, 2) equals Cpython's result (-2, 1).
self += other q -= 1
# t = f.signOf() # if t and t != s: # from pygeodesy.errors import _AssertionError # raise f._Error(_dimo_, other, _AssertionError, txt=signOf.__name__)
'''Get the current, precision running sum (C{float} or C{int}). ''' return self._fsum0
'''Get this instance' C{floor} (C{int} in Python 3+, C{float} in Python 2-).
@note: The C{floor} takes the C{residual} into account.
@see: Properties L{Fsum.ceil}, L{Fsum.float_int}, L{Fsum.imag} and L{Fsum.real}. '''
# floordiv = __floordiv__ # for naming consistency
'''Apply C{B{self} //= B{other}}. '''
'''(INTERNAL) Apply C{B{self} *= B{other}} C{scalar} only. ''' # assert isscalar(other) else: # assert self._ps is ps
'''(INTERNAL) Negate this instance. '''
'''Apply C{B{self} **= B{other}}, optional B{C{mod}}. ''' return self._fpow(other, op) else: except TypeError as x: E, t = _TypeError, str(x) except Exception as x: E, t = _ValueError, str(x) raise self._Error(op, other, E, txt=t) else: raise self._ResidualError(op, other, r) s *= p # C{scalar}s or L{Fsum}s
'''(INTERNAL) Overwrite this instance with an other or a C{scalar}. ''' else: # PYCHOK no cover raise self._TypeError(_fset_, other)
'''Subtract several values.
@arg xs: Iterable, list, tuple. etc. (C{scalar} or L{Fsum} instances).
@return: This instance, updated (L{Fsum}).
@see: Method L{Fsum.fadd}. '''
'''Subtract any positional value.
@arg xs: Values to subtract (C{scalar} or L{Fsum} instances), all positional.
@return: This instance, updated (L{Fsum}).
@see: Method L{Fsum.fadd}. '''
'''Add C{None} or several values and sum all.
@kwarg xs: Iterable, list, tuple, etc. (C{scalar} or L{Fsum} instances).
@return: Precision running sum (C{float} or C{int}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value.
@note: Accumulation can continue after summation. '''
'''Add any positional value and sum all.
@arg xs: Values to add (C{scalar} or L{Fsum} instances), all positional.
@return: Precision running sum (C{float} or C{int}).
@see: Method L{Fsum.fsum}. '''
'''(INTERNAL) Get this instance', memoized precision running sum (C{float} or C{int}), without C{residual}.
@note: The precision running C{fsum} after a C{//=} or C{//} C{floor} division is C{int} in Python 3+.
@see: Method L{Fsum.fsum2} and property L{Fsum.residual}. ''' else: else: # PYCHOK no cover ps[i] = s = p # swap s and p and continue # else: # s = float(s) # assert self._ps is ps # assert self.__dict__.get(Fsum._fsum2.name, None) is None # Fsum._fsum2._update(self)
'''Add C{None} or several values and return the current precision running sum and residual.
@kwarg xs: Iterable, list, tuple, etc. (C{scalar} or L{Fsum} instances).
@return: L{Fsum2Tuple}C{(fsum, residual)} with C{fsum} the current precision running and C{residual}, the sum of the remaining C{partials}.
@see: Methods L{Fsum.fsum} and L{Fsum.fsum2_} '''
'''(INTERNAL) Get this instance', memoized current precision running sum and residual (L{Fsum2Tuple}).
@note: If the C{residual} is C{int(0)}, the precision running C{fsum} is considered to be I{exact}.
@see: Method L{Fsum.fsum} and property L{Fsum.residual}. '''
'''Add any positional value and return the current precision running sum and C{delta}, the increment.
@arg xs: Values to add (C{scalar} or L{Fsum} instances), all positional.
@return: 2-Tuple C{(fsum, delta)} with the current precision running C{fsum} and C{delta}, the difference with the prior running C{fsum} (C{float}s).
@see: Methods L{Fsum.fsum_} and L{Fsum.fsum}. '''
# ftruediv = __itruediv__ # for naming consistency
'''(INTERNAL) Apply C{B{self} /= B{other}}. ''' raise self._ResidualError(op, other, r) # self / (d + r) == self * n / d # n = d / (d + r) = 1 / (1 + r / d) # d' = d / n = d * (1 + r / d), but # is pointless if (1 + r / d) == 1 else: # PYCHOK no cover d = r else: raise self._TypeError(op, other) except ZeroDivisionError as x: raise self._ZeroDivisionError(op, d, txt=str(x)) except (TypeError, ValueError) as x: raise self._ValueError(op, d, txt=str(x))
'''Get the C{imaginary} part of this instance (C{0.0}, always).
@see: Properties L{Fsum.ceil}, L{Fsum.floor} and L{Fsum.real}. '''
'''Is this instance' precision running C{fsum} considered to be exact? (C{bool}). '''
'''Return C{True} if this instance value is C{integer} or C{type(int)}, C{False} otherwise.
@kwarg both: If C{True}, check C{float} types and value, otherwise consider the C{int} single-C{partial} only. ''' else:
'''Return C{True} if functions C{fsum}, C{fsum}_, C{fsum1} and C{fsum1_} are all based on Python's C{math.fsum}, C{False} otherwise. '''
'''(INTERNAL) Return C{B{self} * B{other}} L{Fsum} as L{Fsum}. ''' # assert isinstance(other, Fsum)
'''Get this instance' current partial sums (C{tuple} of C{float}s). '''
'''Return C{B{self}**B{x}} as L{Fsum}.
@arg x: The exponent (L{Fsum} or C{scalar}). @arg mod: Optional modulus (C{int} on C{None}) for the 3-argument C{pow(B{self}, B{other}, B{mod})} version.
@return: The C{pow(self, B{x})} or C{pow(self, B{x}, *B{mod})} result (L{Fsum}).
@note: If B{C{mod}} is given, the result is an C{int} in Python 3+ if this instance C{is_integer}, in particular when B{C{mod}} given as C{None}.
@see: Method L{Fsum.__ipow__}. ''' else: # negative or non-int B{C{x}}
'''(INTERNAL) Return B{C{self}**1} or B{C{self}**0} preserving C{type}. '''
'''(INTERNAL) Return C{B{self}**B{x}} for C{int B{x} >= 0} only. ''' raise self._ValueError(op, x, txt=_SPACE_(_negative_, int.__name__))
else: f = Fsum(_1_0) else: # self**1 or self**0 f = self._pow_0_1(x) else: # 0**non0 == 0, but 0**0 == 1 f = 0 if x else 1
'''(INTERNAL) Return C{self**B{x}} for C{scalar B{x}} only. ''' s, r = s._fsum2 if r: raise self._ResidualError(op, other, r) # use **= -1 for the CPython float_pow # error if s is zero, and not s = 1 / s x = -1 else: else: # self**1 or self**0 raise self._TypeError(op, other, txt=_not_(_scalar_)) raise self._ResidualError(op, other, r) raise self._ValueError(op, other, txt=_not_(_supported_)) except Exception as e: raise self._ValueError(op, other, txt=str(e))
'''(INTERNAL) Yield partials, pseudo-sorted, 1-primed minus C{less} if non-zero. '''
'''(INTERNAL) Yield C{partials}, multiplied by each of the B{C{factors}}. '''
'''Get the C{real} part of this instance (C{float}).
@see: Methods L{Fsum.__float__} and L{Fsum.fsum} and properties L{Fsum.ceil}, L{Fsum.floor}, L{Fsum.imag} and L{Fsum.residual}. '''
'''Get this instance' residual (C{float} or C{int}), the sum of the C{partials} less the precision running sum C{fsum}.
@note: If the C{residual} is C{int(0)}, the precision running C{fsum} is considered to be I{exact}.
@see: Methods L{Fsum.fsum}, L{Fsum.fsum2} and L{Fsum.is_exact}. '''
'''(INTERNAL) Non-zero residual C{ValueError}. '''
'''Determine the sign of this instance.
@kwarg res: If C{True} consider, otherwise ignore the residual (C{bool}).
@return: The sign (C{int}, -1, 0 or +1). '''
'''Return this C{Fsum} instance as representation.
@kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped for B{C{prec}} values of 1 and above, but kept for negative B{C{prec}} values. @kwarg sep: Optional separator to join (C{str}). @kwarg fmt: Optional, C{float} format (C{str}).
@return: This instance (C{str}). '''
'''Return this C{Fsum} instance as string.
@kwarg prec: The C{float} precision, number of decimal digits (0..9). Trailing zero decimals are stripped for B{C{prec}} values of 1 and above, but kept for negative B{C{prec}} values. @kwarg sep: Optional separator to join (C{str}). @kwarg fmt: Optional, C{float} format (C{str}).
@return: This instance (C{repr}). '''
def _TypeError(self, op, other, **txt): # PYCHOK no cover '''(INTERNAL) Operand C{TypeError}. ''' return self._Error(op, other, _TypeError, **txt)
'''(INTERNAL) Copy, set or zap all cached C{Property_RO} values. ''' else: # dup if present, otherwise zap # Property_RO ._fsum0 and ._fsum2 can't be a Property since # Property's _fset zaps the value just set by the @setter
def _ValueError(self, op, other, **txt): # PYCHOK no cover '''(INTERNAL) Return a C{ValueError}. ''' return self._Error(op, other, _ValueError, **txt)
'''(INTERNAL) Return a C{ZeroDivisionError}. '''
'''(INTERNAL) Unit of L{Fsum2Tuple} items. '''
'''2-Tuple C{(fsum, residual)} with the precision running C{fsum} and the C{residual}, the sum of the remaining partials if any. Each item is either C{float} or C{int}. '''
# make sure _fsum works as expected (XXX check # float.__getformat__('float')[:4] == 'IEEE'?) if _fsum((1, 1e101, 1, -1e101)) != 2: # PYCHOK no cover del _fsum # nope, remove _fsum ... raise ImportError # ... use _fsum below
except ImportError:
def _fsum(xs): '''(INTERNAL) Precision summation, Python 2.5-. ''' return Fsum(name=_fsum.__name__)._fadd(xs)._fsum0
'''Precision floating point summation based on or like Python's C{math.fsum}.
@arg xs: Iterable, list, tuple, etc. of values (C{scalar} or L{Fsum} instances).
@return: Precision C{fsum} (C{float}).
@raise OverflowError: Partial C{2sum} overflow.
@raise TypeError: Non-scalar B{C{xs}} value.
@raise ValueError: Invalid or non-finite B{C{xs}} value.
@note: Exceptions and I{non-finite} handling may differ if not based on Python's C{math.fsum}.
@see: Class L{Fsum} and methods L{Fsum.fsum} and L{Fsum.fadd}. '''
'''Precision floating point summation of all positional arguments.
@arg xs: Values to be added (C{scalar} or L{Fsum} instances), all positional.
@return: Precision C{fsum} (C{float}).
@see: Function C{fsum}. '''
'''Precision floating point summation of a few values, 1-primed.
@arg xs: Iterable, list, tuple, etc. of values (C{scalar} or L{Fsum} instances).
@return: Precision C{fsum} (C{float}).
@see: Function C{fsum}. '''
'''Precision floating point summation of a few arguments, 1-primed.
@arg xs: Values to be added (C{scalar} or L{Fsum} instances), all positional.
@return: Precision C{fsum} (C{float}).
@see: Function C{fsum} '''
# **) MIT License # # Copyright (C) 2016-2022 -- mrJean1 at Gmail -- All Rights Reserved. # # Permission is hereby granted, free of charge, to any person obtaining a # copy of this software and associated documentation files (the "Software"), # to deal in the Software without restriction, including without limitation # the rights to use, copy, modify, merge, publish, distribute, sublicense, # and/or sell copies of the Software, and to permit persons to whom the # Software is furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included # in all copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR # OTHER DEALINGS IN THE SOFTWARE. |