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 x and y, 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 x and y, 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 x and y, scaled by s, 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 to relative_error(x, y).

fpy2.libraries.metrics.ordinal_error(x, y)

Computes the ordinal error between x and y, i.e., the number of floating-point numbers between x and y.

This is equivalent to |int(x) - int(y)|, where int is the conversion from Float to int.

Parameters:
  • x (Float) – First value

  • y (Float) – Second value

Returns:

Number of floating-point numbers between x and y

Return type:

Fraction

Raises:

TypeError – if x or y is not a Float or Fraction, or if the context is not an OrdinalContext

Primitive: This is an FPy primitive that requires an OrdinalContext.