Main Content

fixed.unifiedErrorCalculator.bitsOfError

Bits of error of two numeric inputs

Since R2023b

Description

fixed.unifiedErrorCalculator.bitsOfError(approxValue,refValue) returns the bits of error between the approximate value approxValue and the reference value refValue given by (refValue-approxValue)/eps(approxValue).

example

fixed.unifiedErrorCalculator.bitsOfError(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.

Examples

collapse all

Use the fixed.unifiedErrorCalculator.bitsOfError function to compute the bits of error between a set of numerical values in double precision and the same set of values in single precision.

refValue = [-3.99999988079071 -3.9999998807907104 -0.2499999999987,...
    3.99999988079071 3.9999998807907104];
approxValue = single(refValue);
y = fixed.unifiedErrorCalculator.bitsOfError(approxValue,refValue)
y =

   -0.5000    0.5000    0.0001    0.5000   -0.5000

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.

Algorithms

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

  • If approxValue is floating point, then eps(approxValue) returns the floating-point relative accuracy.

  • If approxValue is an integer data type, then eps(approxValue) returns 1.

  • If approxValue is a fi object, then eps(approxValue) returns the quantized relative accuracy for the fi object.

Version History

Introduced in R2023b