简体   繁体   English

为什么IEEE-754浮点数不能在平台之间交换?

[英]Why is IEEE-754 Floating Point not exchangable between platforms?

It has been asserted that (even accounting for byte endian-ness) IEEE754 floating point is not guaranteed to be exchangeable between platforms. 已经断言 (甚至考虑字节字节序)IEEE754浮点并不保证在平台之间可以交换。

So: 所以:

  • Why, theoretically, is IEEE floating point not exchangeable between platforms? 理论上,为什么IEEE浮点不能在平台之间交换?
  • Are any of these concerns valid for modern hardware platforms (eg i686, x64, arm)? 这些问题是否适用于现代硬件平台(例如i686,x64,arm)?

If the concerns are valid, can you please demonstrate an example where this is the case (C or C++ is preferred)? 如果问题是有效的,您能否请举例说明这种情况(首选C或C ++)?


Motivation: Several GPS manufacturers exchange their binary formats for (eg) latitude, longitude and raw data in "IEEE-754 compliant floating point values". 动机:一些GPS 制造商在“符合IEEE-754标准的浮点值”中为(例如)纬度,经度和原始数据交换其二进制格式。 So, I don't have control to choose a text format or other "portable" format. 所以,我无法控制选择文本格式或其他“便携式”格式。 Hence, my question has to when the differences may or may not occur. 因此,我的问题是何时可能会或可能不会发生差异。

IEEE 754 clause 3.4 specifies binary interchange format encodings. IEEE 754第3.4条规定了二进制交换格式编码。 Given a floating-point format (below), the interchange format puts the sign bit in the most significant bit, biased exponent bits in the next most significant bits, and the significand encoding in the least significant bits. 给定浮点格式(下面),交换格式将符号位置于最高有效位中,将下一个最高有效位中的偏置指数位置位,并将有效位编码置于最低有效位中。 A mapping from bits to bytes is not specified, so a system could use little-endian, big-endian, or other ordering. 未指定从位到字节的映射,因此系统可以使用little-endian,big-endian或其他排序。

Clause 3.6 specifies format parameters for various format widths, including 64-bit binary, for which there is one sign bit, 11 exponent field bits, and 52 significand field bits. 第3.6节规定了各种格式宽度的格式参数,包括64位二进制,其中有一个符号位,11个指数字段位和52个有效位字段位。 This clause also specifies the exponent bias. 该子句还规定了指数偏差。

Clauses 3.3 and 3.4 specify the data represented by this format. 第3.3和3.4条规定了该格式所代表的数据。

So, to interchange IEEE-754 floating-point data, it seems systems need only to agree on two things: which format to use (eg, 64-bit binary) and how to get the bits back and forth (eg, how to map bits to bytes for writing to a file or a network message). 因此,为了交换IEEE-754浮点数据,似乎系统只需要就两件事达成一致:使用哪种格式(例如,64位二进制)以及如何来回获取位(例如,如何映射)用于写入文件或网络消息的位到字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM