Metrics
The metrics library provides common error metrics and condition numbers for floating-point analysis.
Error Metrics
- fpy2.libraries.metrics.absolute_error(x, y)
Computes the absolute error between
xandy, i.e.,|x - y|, rounding under the current context.- Parameters:
x (Real) – First value
y (Real) – Second value
- Returns:
Absolute error
|x - y|- Return type:
Real
- fpy2.libraries.metrics.relative_error(x, y)
Computes the relative error between
xandy, i.e.,|x - y| / |y|, rounding under the current context.- Parameters:
x (Real) – First value (approximate)
y (Real) – Second value (reference)
- Returns:
Relative error
|x - y| / |y|- Return type:
Real
- fpy2.libraries.metrics.scaled_error(x, y, s)
Computes the scaled error between
xandy, scaled bys, i.e.,|x - y| / |s|, rounding under the current context.- Parameters:
x (Real) – First value
y (Real) – Second value
s (Real) – Scaling factor
- Returns:
Scaled error
|x - y| / |s|- Return type:
Real
Note: When
s = y, this is equivalent torelative_error(x, y).
- fpy2.libraries.metrics.ordinal_error(x, y)
Computes the ordinal error between
xandy, i.e., the number of floating-point numbers betweenxandy.This is equivalent to
|int(x) - int(y)|, whereintis the conversion fromFloattoint.- Parameters:
- Returns:
Number of floating-point numbers between x and y
- Return type:
Fraction
- Raises:
TypeError – if
xoryis not a Float or Fraction, or if the context is not an OrdinalContext
Primitive: This is an FPy primitive that requires an OrdinalContext.