Main Content

fixed.unifiedErrorCalculator.absoluteError

Absolute error of two numeric inputs

Since R2023b

Description

fixed.unifiedErrorCalculator.absoluteError(approxValue,refValue) returns the absolute error between the approximate value approxValue and the reference value refValue given by abs(refValue-approxValue).

example

fixed.unifiedErrorCalculator.absoluteError(approxValue,refValue,keepNaN) specifies whether to keep the calculated error as NaN. By default, to indicate the calculated error is significant, the function returns Inf if the calculated error is NaN.

fixed.unifiedErrorCalculator.absoluteError(approxValue,refValue,keepNaN,compMode) specifies whether to use the slower but more accurate computation mode. When either of the inputs is not a MATLAB® built-in type and not a subset of double, the absolute error cannot be computed in double without loss and may not be representable by the double data type. In this case, you can use the fi object to store the absolute error without loss.

Examples

collapse all

Use the fixed.unifiedErrorCalculator.absoluteError function to compute the absolute error between a set of numerical values in double precision and the same set of values quantized to the int8 data type.

refValue = [-129 -128.5 -1.863 0 0.499 125.5 200];
approxValue = int8(refValue);
y = fixed.unifiedErrorCalculator.absoluteError(approxValue,refValue)
y =

    1.0000    0.5000    0.1370         0    0.4990    0.5000   73.0000

Input Arguments

collapse all

Approximate or quantized value, specified as a scalar, vector, matrix, or multidimensional array. The input arguments approxValue and refValue must be real-valued and have the same size.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Reference, ideal, or actual value to compare against, specified as a scalar, vector, matrix, or multidimensional array. The input arguments refValue and approxValue must be real-valued and have the same size.

Data Types: half | single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | fi

Whether to keep NaN results, specified as one of these values:

  • false or 0 — If the calculated error is NaN, return Inf to indicate that the calculated error is significant.

  • true or 1 — If the calculated error is NaN, return NaN.

Computation mode, specified as one of these values:

  • fast — The computed absolute error is of double-precision type. Internal computations use either full-precision double or fixed-point data types, depending of the data types of the inputs. However, when either of the inputs is not a MATLAB built-in type and not a subset of double, the absolute error may not be representable by the double data type.

  • slowAccurate — When either of the inputs is not a MATLAB built-in type and not a subset of double, the computed absolute error is stored as a fi object. This mode is slower but gives more accurate results for some cases.

More About

collapse all

Algorithms

  • If both refValue and approxValue are NaN, Inf, or -Inf, they are treated as equal, and the calculated error is zero.

Version History

Introduced in R2023b