ULP Considerations of Native Floating-Point Operators - MATLAB & Simulink (original) (raw)

Main Content

The representation of infinitely real numbers with a finite number of bits requires an approximation. This approximation can result in rounding errors in floating-point computation. To measure the rounding errors, the floating-point standard uses relative error and ULP (Units in the Last Place) error. To learn about relative error, see Relative Accuracy and ULP Considerations.

If the exponent range is not upper-bounded, Units in Last Place (ULP) of a floating-point number x is the distance between two closest straddling floating-point numbers a and b nearest to x. The IEEE-754 standard requires that the result of an elementary arithmetic operation such as addition, multiplication, and division is correctly round. A correctly rounded result means that the rounded result is within 0.5 ULP of the exact result.

Adherence of Native Floating Point Operators to IEEE-754 Standard

Native floating point technology in HDL Coder™ follows IEEE® standard of floating-point arithmetic. Basic arithmetic operations such as addition, subtraction, multiplication, division, and reciprocal are mandated by IEEE to have zero ULP error. When you perform these operations in native floating-point mode, the numerical results obtained from the generated HDL code match the original Simulink® model.

Certain advanced math operations such as exponential, logarithm, and trigonometric operators have machine-specific implementation behaviors because these operators use recurring Taylor series and Remez expression based implementations. When you use these operators in native floating-point mode, there can be relatively small differences in numerical results between the Simulink model and the generated HDL code.

You can measure the difference in numerical results as a relative error or ULP. A nonzero ULP for these operators does not mean noncompliance with the IEEE standard. A ULP of one is equivalent to a relative error of10^-7. You can ignore such relatively small errors by specifying a custom tolerance value for the ULP when generating a HDL test bench. For example, you can specify a custom floating-point tolerance of one ULP to ignore the error when verifying the generated code. For more information, see configuration parameters Floating point tolerance check based on and Tolerance Value.

ULP Values of Floating Point Operators

The table enumerates the ULP of floating-point operators that have a nonzero ULP.

Math Functions

Simulink Blocks Data Type Units in the Last Place (ULP) error
exp Single 1
Half 1
log Double 1
Single 1
Half 1
log10 Single 1
Half 1
10^u Single 1
pow Single 1
hypot Single 1

Math Operations

Simulink Blocks Data Type Units in the Last Place (ULP) error
Sqrt Double 1

Considerations

For certain floating-point input values, some blocks can produce simulation results that vary from the MATLAB® simulation results. To see the difference in results, before you generate code, enable generation of the validation model. In the Configuration Parameters dialog box, on the HDL Code Generation pane, select the Generate validation model check box.

See Also

Modeling Guidelines

Functions

Topics