简体   繁体   English

除IEEE754之外,是否还有其他常用的浮点格式?

[英]Are there any commonly used floating point formats besides IEEE754?

I am writing a marshaling layer to automatically convert values between different domains. 我正在编写一个封送处理层,以在不同域之间自动转换值。 When it comes to floating point values this potentially means converting values from one floating point format to another. 当涉及浮点值时,这可能意味着将值从一种浮点格式转换为另一种。 However, it seems that almost every modern system is using IEEE754, so I'm wondering whether it's actually worth generalising to allow other formats, or just manage marshaling between different IEEE754 formats. 但是,似乎几乎每个现代系统都在使用IEEE754,因此我想知道是否值得推广其他格式,或者仅管理不同IEEE754格式之间的封送处理。

Does anyone know of any commonly used floating point formats other than IEEE754 that I should consider (perhaps on ARM processors or mainframes)? 有谁知道我应该考虑的除IEEE754之外的任何常用浮点格式(也许在ARM处理器或大型机上)? If so, a reference to the format specification would be extremely helpful. 如果是这样,则对格式规范的引用将非常有帮助。

Virtually all relatively modern (within the last 15 years) general purpose computers use IEEE 754. In the very unlikely event that you find system that you need to support which uses a non-IEEE 754 floating point format, there will probably be a library available to convert to/from IEEE 754. 几乎所有相对较新的(过去15年内)通用计算机都使用IEEE754。在极少数情况下,如果您发现需要支持的系统使用非IEEE 754浮点格式,则可能会有可用的库与IEEE 754相互转换。

Some non-ancient systems which did not natively use IEEE 754 were the Cray SV1 (1998-2003) and IBM System 360, 370, and 390 prior to Generation 5 (ended 2002). 第五代(2002年末)之前的一些非古老系统,其本机未使用IEEE 754,它们是Cray SV1(1998-2003)和IBM System 360、370和390。 IBM implemented IEEE 754 emulation around 2001 in a software release for prior S/390 hardware. IBM在2001年前后在用于先前S / 390硬件的软件版本中实现了IEEE 754仿真

As of now, what systems do you actually want this to work on? 截至目前,您实际上希望该系统在什么系统上运行? If you come across one down the line that doesn't use IEEE754 (which as @JohnZwinick says, is vanishingly unlikely) then you should be able to code for that then. 如果碰到一个不使用IEEE754的线路(就像@JohnZwinick所说的那样,这种情况就几乎消失了),那么您应该能够对此进行编码。

To put it another way, what you are designing here is, in effect, a communications protocol and you obviously seek to make a sensible choice for how you will represent a floating point number (both single precision and double precision, I guess) in the bytes that travel between domains. 换句话说,实际上,您在这里设计的是一种通信协议,并且您显然希望做出明智的选择,以表示如何在浮点数中表示浮点数(我想是单精度和双精度)。域之间传输的字节数。

I think @SomeProgrammerDude was trying to imply that representing these as text strings (while they are in transit) might offer the most portability, and if so I would agree, but it's obviously not the most efficient way to do it. 我认为@SomeProgrammerDude试图暗示将它们表示为文本字符串(在传输过程中)可能会提供最大的可移植性,如果可以的话,我同意,但这显然不是最有效的方法。

So, if you do decide to plump for IEEE754 as your interchange format (as I would) then the worst that can happen is that you might need to find a way to convert these to and from the native format used on some antique architecture that you are almost certainly never going to encounter, and if that does happen then that problem would not be not difficult to solve . 因此,如果您确实决定像往常一样将IEEE754作为交换格式,那么可能发生的最坏情况是您可能需要找到一种方法,将它们转换为与您使用的某些老式体系结构所使用的本机格式之间的转换。几乎可以肯定,它们永远都不会遇到,如果确实发生了,那么解决这个问题就不会困难

Also, floats and doubles can be big-endian or little-endian, so you need to decide what you're going to use in your byte stream and convert when marshalling if necessary. 另外,浮点数和双精度数可以是大端或小端,因此您需要确定要在字节流中使用的内容,并在必要时进行编组时进行转换。 Little-endian is much more common these days so I'd go with that. 如今,小尾数(Little-endian)更常见,所以我会同意的。

Does anyone know of any commonly used floating point formats other than IEEE754 that I should consider ...? 有谁知道我应该考虑的除IEEE754以外的任何常用浮点格式?

  1. CCSI uses a variation on binary32 for select processors. CCSI使用binary32的变体选择处理器。

it seems that almost every modern system is using IEEE754, 似乎几乎每个现代系统都使用IEEE754,

  1. Yes, but... various implementations fudge on the particulars with edge values like subnormals , negative zero in visual studio , infinity and not-a-number . 是的,但是...各种实现对边缘细节的伪造 ,例如次法线Visual Studio中的负零,无穷大和非数字

It is this second issue that is more lethal and harder to discern that a given implementation has completely coded IEEE754. 第二个问题更致命,更难辨认给定的实现已完全编码IEEE754。 See __STDC_IEC_559__ 参见__STDC_IEC_559__

OP has "I am writing a marshaling layer". OP具有“我正在编写封送处理层”。 It is in this coding that likely troubles remain for edge cases. 正是在这种编码中,边缘情况仍然可能存在问题。 Also IEEE754 does not specify endian so that marshaling issues remains. 同样,IEEE754没有指定字节序,因此封送处理问题仍然存在。 Recall integer endian may not match FP endian . 调用整数字节序可能与FP字节序不匹配。

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

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