如何检查IEEE 754单precision(32位)浮点再presentation用?浮点、IEEE、precision、presentation

2023-09-11 23:08:50 作者:①起地荖兲巟

我想测试下的东西对我的目标板上:

I want to test the following things on my target board:

是'浮动'与IEEE 754单precision(32位)实现浮点变量? 是双师型与IEEE 754双precision(64位)浮点变量来实现?

什么是我可以用一个简单的C程序进行测试的方式。

What are the ways in which i can test it with a simple C program.

推荐答案

没有简单的测试存在。

系统今天,绝大多数使用IEEE-754格式的浮点。然而,大多数C实现不完全符合IEEE 754(这是等同于IEC 60559),并没有设置preprocessor标识符 __ STDC_IEC_559 __ 。如果没有这个标识的,只有这样,才能确定一个C实现是否符合IEEE 754是一种或组合:

The overwhelming majority of systems today use IEEE-754 formats for floating-point. However, most C implementations do not fully conform to IEEE 754 (which is identical to IEC 60559) and do not set the preprocessor identifier __STDC_IEC_559__. In the absence of this identifier, the only way to determine whether a C implementation conforms to IEEE 754 is one or a combination of:

在阅读它的文档。 在检查其来源$ C ​​$ C。 在测试它(这是当然的,困难的时候只有详尽的测试是决定性的)。

在许多C实现和应用软件,从IEEE 754的偏差可以被忽略或合作周围:你可以写code,如果IEEE 754人在使用,很多code将在很大程度上正常工作。不过,也有各种各样的事情可以绊倒不知情的程序员;书写完全正确的浮点code是困难的,即使完整的规范得到遵守。

In many C implementations and software applications, the deviations from IEEE 754 can be ignored or worked around: You may write code as if IEEE 754 were in use, and much code will largely work. However, there are a variety of things that can trip up an unsuspecting programmer; writing completely correct floating-point code is difficult even when the full specification is obeyed.

常见的偏差包括:

在中间运算与多precision比标称的类型进行。例如,使用值可以计算长双 precision EX pressions。 开方不会在任何情况下返回正确舍入的值。 在其他的数学库函数返回的正确,可能是稍微偏离值(几ULP)四舍五入的结果。 (事实上​​,没有人实现的所有建议的IEEE 754-2008既保证正确的舍入的数学程序,并保证约束的运行时间。) 次正规号码(浮点格式的边缘附近微小号码)可被转换到零,而不是处理为指定由IEEE 754。 在转换十进制数之间(例如, 3.1415926535897932384626433 源$ C ​​$ c)和二进制浮点格式(例如,常见的格式,IEEE-754 64位二进制)并不总是正确全面,在任一转换方向。 仅舍入到最接近模式的支持;中不支持IEEE 754中指定的其他舍入模式。或者它们可以是可用于简单算术,但需要使用机器特定汇编语言来访问。标准数学库( COS 日志,等等)很少支持其它舍入模式。 Intermediate arithmetic is performed with more precision than the nominal type. E.g., expressions that use double values may be calculated with long double precision. sqrt does not return a correctly rounded value in every case. Other math library routines return values that may be slightly off (a few ULP) from the correctly rounded results. (In fact, nobody has implemented all the math routines recommended in IEEE 754-2008 with both guaranteed correct rounding and guaranteed bound run time.) Subnormal numbers (tiny numbers near the edge of the floating-point format) may be converted to zero instead of handled as specified by IEEE 754. Conversions between decimal numerals (e.g., 3.1415926535897932384626433 in the source code) and binary floating-point formats (e.g., the common double format, IEEE-754 64-bit binary) do not always round correctly, in either conversion direction. Only round-to-nearest mode is supported; the other rounding modes specified in IEEE 754 are not supported. Or they may be available for simple arithmetic but require using machine-specific assembly language to access. Standard math libraries (cos, log, et cetera) rarely support other rounding modes.