为什么IEEE-754浮点不能在平台之间互换? [英] Why is IEEE-754 Floating Point not exchangable between platforms?

查看:135
本文介绍了为什么IEEE-754浮点不能在平台之间互换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

声明 (即使考虑到字节的字节序),也不保证IEEE754浮点可以在平台之间互换.

It has been asserted that (even accounting for byte endian-ness) IEEE754 floating point is not guaranteed to be exchangeable between platforms.

所以:

  • 从理论上讲,为什么平台之间不能交换IEEE浮点 ?
  • 这些关注点是否对现代硬件平台(例如i686,x64,arm)有效?

如果这些担心是正确的,请您举个例子说明这种情况(首选C或C ++)吗?

If the concerns are valid, can you please demonstrate an example where this is the case (C or C++ is preferred)?

动机:几个 GPS

Motivation: Several GPS manufacturers exchange their binary formats for (e.g.) latitude, longitude and raw data in "IEEE-754 compliant floating point values". 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条款3.4指定了二进制交换格式编码.给定浮点格式(如下所示),互换格式将符号位放在最高有效位中,将偏置指数位放在接下来的最高有效位中,并将有效位编码放入最低有效位中.没有指定从位到字节的映射,因此系统可以使用小尾数,大尾数或其他顺序.

IEEE 754 clause 3.4 specifies binary interchange format encodings. 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.

条款3.6指定了各种格式宽度的格式参数,包括64位二进制文​​件,其中有一个符号位,11个指数字段位和52个有效字段位.此子句还指定了指数偏差.

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. This clause also specifies the exponent bias.

第3.3和3.4条指定了此格式表示的数据.

Clauses 3.3 and 3.4 specify the data represented by this format.

因此,要交换IEEE-754浮点数据,似乎系统只需要在两件事上达成共识:要使用哪种格式(例如64位二进制)以及如何来回获取这些比特(例如,如何将位映射为字节以写入文件或网络消息.

So, to interchange IEEE-754 floating-point data, it seems systems need only to agree on two things: which format to use (e.g., 64-bit binary) and how to get the bits back and forth (e.g., how to map bits to bytes for writing to a file or a network message).

这篇关于为什么IEEE-754浮点不能在平台之间互换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆