Package pygeodesy :: Module fmath |
[frames] | no frames]

# Module fmath

Precision mathematical functions, utilities and constants.

Version: 18.09.14

Classes
| Fsum Precision floating point summation similar to standard Python function math.fsum.

Functions
hypot(x, y) Return the Euclidean distance, sqrt(x*x + y*y). |
cbrt(x) Compute the cubic root x**(1/3). |
cbrt2(x) Compute the cubic root squared x**(2/3). |
favg(v1, v2, f=0.5) Return the weighted average of two values. |
fdot(a, *b) Return the precision dot product sum(a[i] * b[i] for i=0..len(a)). |
fdot3(a, b, c, start=0) Return the precision dot product start + sum(a[i] * b[i] * c[i] for i=0..len(a)). |
fhorner(x, *cs) Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)) using the Horner form. |
fmean(xs) Compute the accurate mean sum(xs[i] for i=0..len(xs)) / len(xs). |
fpolynomial(x, *cs) Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)). |
fpowers(x, n, alts=0) Return a series of powers [x**i for i=1..n]. |
fStr(floats, prec=6, sep=`'``,` `'`, fmt=`'``%.*f``'`, ints=False) Convert floats to string, optionally with trailing zero decimals stripped. |
fStrzs(fstr) Strip trailing zero decimals from a float string. |
fsum_(*args) Precision floating point summation of the positional arguments. |
fsum(iterable) Return an accurate floating point sum of values in the iterable. |
hypot1(x) Compute the norm sqrt(1 + x**2). |
hypot3(x, y, z) Compute the norm sqrt(x**2 + y**2 + z**2). |
isfinite(obj) Check for Inf and NaN values. |
isint(obj, both=False) Check for integer type or integer value. |
isscalar(obj) Check for scalar types. |
len2(seq) Make built-in function `len` work for generators, iterators, etc. |
map1(func, *args) Apply each argument to a single-argument function and return a tuple of results. |
map2(func, *args) Apply arguments to a function and return a tuple of results. |
scalar(value, low=2.22044604925e-16, high=1.0, name=`'``scalar``'`) Validate a scalar. |
sqrt3(x) Compute the square root cubed sqrt(x)**3 or sqrt(x**3). |

Variables
| EPS = `2.22044604925e-16` Approximate epsilon (float)
| EPS1 = `1.0` 1 - EPS (float), about 0.9999999999999998
| EPS2 = `1.49011611938e-08` sqrt(EPS) (float)

Function Details

### cbrt(x) |
Compute the cubic root x**(1/3). Parameters: `x` - Value (scalar). Returns: Cubic root (float).

### cbrt2(x) |
Compute the cubic root squared x**(2/3). Parameters: `x` - Value (scalar). Returns: Cubic root squared (float). See Also: Function sqrt3.

### favg(v1, v2, f=0.5) |
Return the weighted average of two values. Parameters: `v1` - One value (scalar). `v2` - Other value (scalar). `f` - Optional fraction (scalar). Returns: v1 + f * (v2 - v1) (float).

### fdot(a, *b) |
Return the precision dot product sum(a[i] * b[i] for i=0..len(a)). Parameters: `a` - List, sequence, tuple, etc. (scalars). `b` - All positional arguments (scalars). Returns: Dot product (float). Raises: `ValueError` - Unequal len(a) and len(b).

### fdot3(a, b, c, start=0) |
Return the precision dot product start + sum(a[i] * b[i] * c[i] for i=0..len(a)). Parameters: `a` - List, sequence, tuple, etc. (scalars). `b` - List, sequence, tuple, etc. (scalars). `c` - List, sequence, tuple, etc. (scalars). `start` - Optional bias (scalar). Returns: Dot product (float). Raises: `ValueError` - Unequal len(a), len(b) and/or len(c).

### fhorner(x, *cs) |
Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)) using the Horner form. Parameters: `x` - Polynomial argument (scalar). `cs` - Polynomial coeffients (scalars). Returns: Horner value (float). Raises: `TypeError` - Argument x not scalar. `ValueError` - No cs coefficients.

### fmean(xs) |
Compute the accurate mean sum(xs[i] for i=0..len(xs)) / len(xs). Parameters: `xs` - Values (scalars). Returns: Mean value (float). Raises: `ValueError` - No xs values.

### fpolynomial(x, *cs) |
Evaluate the polynomial sum(cs[i] * x**i for i=0..len(cs)). Parameters: `x` - Polynomial argument (scalar). `cs` - Polynomial coeffients (scalars). Returns: Polynomial value (float). Raises: `TypeError` - Argument x not scalar. `ValueError` - No cs coefficients.

### fpowers(x, n, alts=0) |
Return a series of powers [x**i for i=1..n]. Parameters: `x` - Value (scalar). `n` - Highest exponent (int). `alts` - Only alternating powers, starting with this exponent (int). Returns: Powers of x (list of floats). Raises: `TypeError` - Argument x not scalar or n not int. `ValueError` - Argument n not positive.

### fStr(floats, prec=6, sep=`'``,` `'`, fmt=`'``%.*f``'`, ints=False) |
Convert floats to string, optionally with trailing zero decimals stripped. Parameters: `floats` - List, sequence, tuple, etc. (scalars). `prec` - Optional precision, number of decimal digits (0..9). Trailing zero decimals are stripped for prec values of 1 and above, but kept for negative prec values. `sep` - Optional, separator to join (string). `fmt` - Optional, float format (string). `ints` - Optionally, remove decimal dot (bool). Returns: The floats as 'f, f, ... f' (string).

### fStrzs(fstr) |
Strip trailing zero decimals from a float string. Parameters: `fstr` - Float (string). Returns: Float (string).

### fsum_(*args) |
Precision floating point summation of the positional arguments. Parameters: `args` - Values to be added (scalars). Returns: Precision fsum (float). Raises: `OverflowError` - Partial 2sum overflow. `ValueError` - Invalid or infinite args value.

### fsum(iterable) |
Return an accurate floating point sum of values in the iterable. Assumes IEEE-754 floating point arithmetic.

### hypot1(x) |
Compute the norm sqrt(1 + x**2). Parameters: `x` - Argument (scalar). Returns: Norm (float).

### hypot3(x, y, z) |
Compute the norm sqrt(x**2 + y**2 + z**2). Parameters: `x` - X argument (scalar). `y` - Y argument (scalar). `z` - Z argument (scalar). Returns: Norm (float).

### isfinite(obj) |
Check for Inf and NaN values. Parameters: `obj` - Value (scalar). Returns: False if Inf or NaN, True otherwise (bool). Raises: `TypeError` - If obj value is not scalar.

### isint(obj, both=False) |
Check for integer type or integer value. Parameters: `obj` - The object (any). `both` - Optionally, check both type and value (bool). Returns: True if obj is integer (bool).

### isscalar(obj) |
Check for scalar types. Parameters: `obj` - The object (any). Returns: True if obj is scalar (bool).

### len2(seq) |
Make built-in function `len` work for generators, iterators, etc. since those can only be started once. Parameters: `seq` - Generator, iterator, list, range, tuple, etc. Returns: 2-Tuple (number, list) of items (int, list).

### map1(func, *args) |
Apply each argument to a single-argument function and return a tuple of results. Parameters: `func` - Function to apply (callable). `args` - Arguments to apply (any positional). Returns: Function results (tuple).

### map2(func, *args) |
Apply arguments to a function and return a tuple of results. Unlike Python 2's built-in `map`, Python 3+ `map` returns a `map` object, an iterator-like object which generates the results only once. Converting the `map` object to a tuple maintains Python 2 behavior. Parameters: `func` - Function to apply (callable). `args` - Arguments to apply (list, tuple, ...). Returns: N-Tuple of function results (tuple).

### scalar(value, low=2.22044604925e-16, high=1.0, name=`'``scalar``'`) |
Validate a scalar. Parameters: `value` - The value (scalar). `low` - Optional lower bound (scalar). `high` - Optional upper bound (scalar). `name` - Optional name of value (string). Returns: New value (type(low)). Raises: `TypeError` - The value is not scalar. `ValueError` - The value is out of bounds.

### sqrt3(x) |
Compute the square root cubed sqrt(x)**3 or sqrt(x**3). Parameters: `x` - Value (scalar). Returns: Cubid square root (float). Raises: `ValueError` - Negative x. See Also: Function cbrt2.