Main Content

ULP Considerations of Native Floating-Point Operators

无限的表示实数一个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相对准确性和ULP考虑

如果指数范围不符合上限,则浮点数x的最后一个位置(ULP)的单位是两个最接近两个最接近的浮点数a和b的距离。IEEE-754标准要求基本算术操作(例如加法,乘法和除法)的结果正确。正确的圆形结果意味着圆形结果在确切结果的0.5 ULP之内。

本地浮点操作员遵守IEEE-754标准

HDL Coder™中的本地浮点技术遵循浮点算术的IEEE标准。IEEE要求基本的算术操作,例如加法,减法,乘法,除法和倒数,以零ULP误差。当您以本机浮点模式执行这些操作时,从生成的HDL代码获得的数值结果与原始Simulink匹配金宝app®模型。

某些高级数学操作,例如指数,对数和三角运算符具有机器特定的实现行为,因为这些运营商使用了重复出现的Taylor系列和基于Remez表达式的实现。当您在本机浮点模式下使用这些操作员时,Simulink模型和生成的HDL代码之间的数值结果可能会有相对较小的差异。金宝app

您可以将数值结果的差异视为相对错误或ULP。这些操作员的非零ULP并不意味着不符合IEEE标准。一个ULP等同于相对误差10^-7。您可以通过在生成HDL测试工作台时指定ULP的自定义公差值来忽略此类相对较小的错误。例如,您可以在验证生成的代码时指定一个ULP的自定义浮点公差,以忽略错误。有关更多信息,请参阅Floating-Point Tolerance Parameters

ULP Values of Floating Point Operators

该表列举了具有非零ULP的浮点运算符的ULP。除了这些操作员,HDL Reciprocal块有五个ULP。

数学功能s

Simulink Blocks Units in the Last Place (ULP) error
经验 1
log 1
log10 2
10^u 1
战俘 1
HYPOT 1

三角函数

Simulink Blocks Units in the Last Place (ULP) error
2
cos 2
tan 3
asin 2
一个cos 2
一个tan 2
atan2 5
2
cosh 1
2
asinh 2
Acosh 2
一个坦 3
罪cos 2

考虑因素

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 theHDL代码生成窗格,选择生成验证模型复选框。

  • 如果您执行涉及复数和例外的计算Infor,具有天然浮点的HDL仿真结果可能与Simulink仿真结果有所不同。金宝app例如,如果您将复杂的输入乘以Inf, the Simulink simulation result isInfiwhereas the HDL simulation result isNan+Infi

  • HDL Coder does not generate a mismatch error between reference and native floating-point values if both values are

  • 如果计算负数的平方根或对数,则使用本机浮点的HDL模拟结果为0。This result matches the simulation result when you verify the design with a SystemVerilog DPI test bench. In Simulink, the result obtained is。根据IEEE-754标准,如果计算负数的平方根或对数,则结果是该数字本身。

  • If the input to the直接查找表(N-D)is of floating-point data type, but the elements of the table use a smaller data type, the generated HDL code can be potentially incorrect. For example, the input is of单身的类型和元素使用UINT8类型。为了获得准确的HDL仿真结果,请为输入信号和查找表的元素使用相同的数据类型。

  • If you use theCosineblock with the inputs-7.729179E28or7.729179E28,生成的HDL代码的ULP为4。对于所有其他输入,ULP为2。

  • 当您使用数学功能块要计算mod(a,b)orREM(A,B), 在哪里一个is the dividend andbis the divisor, the simulation result in native floating-point point mode varies from the MATLAB simulation result in these cases:

    • If b is integer and 一个 b > 2 32 , the simulation result in native floating-point mode is zero. For such significant difference in magnitude between the numbers一个一个ndb,此实现将区域保存在目标FPGA设备上。

    • If 一个 b is close to 2 23 ,在天然浮点模式下的仿真结果可能与MATLAB模拟结果有所不同。

也可以看看

建模指南

功能

相关示例

更多关于