本文介绍了C ++编译器中存在哪些不常见的浮点大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++ 14草案标准对于float,double和long double的特定要求似乎比较安静,尽管这些大小似乎很常见:

The C++14 draft standard seems rather quiet about the specific requirements for float, double and long double, although these sizes seem to be common:

  • float:IEEE 32位浮点表示形式(大约7位精度,指数范围为1e-38..1e + 38)

  • float: IEEE 32-bit floating-point representation (roughly 7 digits of precision, exponent range of 1e-38..1e+38)

double:IEEE 64位浮点表示形式(大约16位精度,指数范围为1e-308..1e + 308)

double: IEEE 64-bit floating-point representation (roughly 16 digits of precision, exponent range of 1e-308..1e+308)

long double:80位浮点表示形式(大约19位精度,指数范围为1e-4951..1e + 4932)

long double: 80-bit floating-point representation (roughly 19 digits of precision, exponent range of 1e-4951..1e+4932)

除这些以外,当前有哪些C ++编译器和系统使用浮点大小?

What C++ compilers and systems currently use floating-point sizes other than these?

我对使用标准类型而不是库的更长,更短和非二进制表示感兴趣,因为我的主要兴趣是C ++程序的可移植性.

I'm interested in longer, shorter, and non-binary representations using the standard types, not libraries, as my primary interest is portability of C++ programs.

推荐答案

如果仅询问以位为单位的大小,那么奇数大小的类型仅存在于一些不使用的旧平台中8位(或2的幂)字节,如 Unisys ClearPath Dorado服务器,具有36位浮点数和72位双倍的.直到现在,那只野兽仍处于活跃的发展之中. 最新版本是在2018年.大型机和服务器的寿命很长,因此您仍然可以看到一些PDP-10和其他架构在现代中正在使用,并具有现代编译器支持

If you're only asking about size in bits then odd-sized types only exist in some older platforms that don't use 8-bit (or another power of 2) bytes like the Unisys ClearPath Dorado Servers with 36-bit float and 72-bit double. That beast is still even in active development until now. The last version was in 2018. Mainframes and servers live a very long life so you can still see some PDP-10 and other architectures in use in modern times, with modern compiler support

如果您在意 formats ,那么有很多标准兼容的32位,64位和128位浮点格式不是十六进制和十进制浮点类型格式 VAX格式.实际上,IBM z是使用十进制浮点硬件的非常罕见的现代平台之一,尽管如果使用GCC和其他一些编译器,则可以使用其对十进制浮点数的内置软件支持. IBM还使用特殊的double-double格式,到目前为止,仍是PowerPC上long double的默认格式

If you care about the formats then there are lots of standard compliant 32, 64 and 128-bit floating-point formats that aren't IEEE-754 like the hex and decimal floating point types in IBM z, Cray formats and VAX formats. In fact IBM z is one of the very rare modern platforms with decimal float hardware, although if you use GCC and some other compilers you can use their built-in software support for decimal float. IBM also uses the special double-double format which is still the default for long double on PowerPC until now

一些用于微控制器的现代C/C ++编译器中还有其他一些非标准的24位浮点数

There are also some other non-standard 24-bit floats in a few modern C/C++ compilers for microcontrollers

以下是大多数可用的浮点格式的摘要.另请参见是否有任何现实中的CPU不使用IEEE 754?.有关更多信息,请继续下一节

Here's the summary of most of the available floating-point formats. See also Do any real-world CPUs not use IEEE 754?. For more information continue to the next section

类型映射到硬件类型.因此,如果有FPU,则浮点类型将是CPU上可用的任何值.在现代计算机中,IEEE-754是硬件中的主要格式,并且由于C ++标准floatdouble的要求,必须至少将其映射到IEEE-754 双精度分别

Types in C++ are generally mapped to hardware types for performance reasons. Therefore floating-point types will be whatever available on the CPU if it ever has an FPU. In modern computers IEEE-754 is the dominant format in hardware, and due to the requirements in C++ standard float and double must be mapped to at least IEEE-754 single and double precision respectively

除了x86和其他一些具有 80位扩展精度,因此在这些平台上, long double通常映射为与double 相同的类型.但是,最近long double正在缓慢地迁移到 IEEE-754四倍精度许多编译器,例如GCC或Clang.由于该程序是使用内置的软件库实现的,因此性能会大大降低.根据您是希望更快的执行速度还是更高的精度,仍然可以自由选择long double映射到的类型.例如,在x86上,GCC具有 -mlong-double-64/80/128-m96/128bit-long-double选项设置long double的填充和格式.该选项在许多其他体系结构中也可用,例如 S/390和zSeries

Hardware support for types with higher precision is not common except on x86 and a few other rare platforms with 80-bit extended precision, therefore long double is usually mapped to the same type as double on those platforms. However recently long double is being slowly migrated to IEEE-754 quadruple precision in many compilers like GCC or Clang. Since that one is implemented with the built-in software library, performance is a lot worse. Depending on whether you favor faster execution or higher precision you're still free to choose whatever type long double maps to though. For example on x86 GCC has -mlong-double-64/80/128 and -m96/128bit-long-double options to set the padding and format of long double. The option is also available in many other architectures like the S/390 and zSeries

默认情况下,PowerPC OTOH使用完全不同的128位长双精度格式,该格式是通过双精度双精度算法,其范围与IEEE-754双精度精度相同.它的精度略低于四倍精度,但速度更快,因为它可以利用硬件双重运算.如上所述,您可以在两种格式之间选择 -mabi=ibmlongdouble/ieeelongdouble选项.在某些仅支持32位浮点数的平台上也使用了这种技巧,以获得接近两倍的精度

PowerPC OTOH by default uses a completely different 128-bit long double format implemented using double-double arithmetic and has the same range as IEEE-754 double precision. Its precision is slightly lower than quadruple precision but it's a lot faster because it can utilize the hardware double arithmetic. As above, you can choose between the 2 formats with the -mabi=ibmlongdouble/ieeelongdouble options. That trick is also used in some platforms where only 32-bit float is supported to get near-double precision

IBM z大型机通常使用 IBM十六进制浮点格式,如今它们仍在使用.但是它们也支持IEEE -754以外的-754二进制和十进制浮点类型

IBM z mainframes traditionally use IBM hex float formats and they still use it nowadays. But they do also support IEEE-754 binary and decimal floating-point types in addition to that

浮点数字

其他体系结构可能具有其他浮点格式,例如VAX或Cray.但是,由于这些大型机仍在使用,它们的较新的硬件版本也包括对IEEE-754的支持,就像IBM对其大型机所做的那样.

Other architectures may have other floating-point formats, like VAX or Cray. However since those mainframes are still being used, their newer hardware version also include support for IEEE-754 just like how IBM did with their mainframes

在没有FPU的现代平台上,浮点类型通常为IEEE-754单精度和双精度,以实现更好的互操作性和库支持.但是,在8位微控制器上,即使单精度也太昂贵了,因此某些编译器支持非标准模式,其中float是24位类型.例如, XC8编译器使用 24位浮点格式是32位格式的截断形式,并且 NXP的MRK使用不同的24位浮点格式

On modern platforms without FPU the floating-point types are usually IEEE-754 single and double precision for better interoperability and library support. However on 8-bit microcontrollers even single precision is too costly, therefore some compilers support a non-standard mode where float is a 24-bit type. For example the XC8 compiler uses a 24-bit floating-point format that is a truncated form of the 32-bit format, and NXP's MRK uses a different 24-bit float format

由于需要更窄浮点类型的图形和AI应用程序的兴起,许多平台还引入了诸如IEEE-754 binary16和Google的bfloat16之类的16位浮点格式,并且编译器也对其提供了有限的支持,例如GCC中的 __fp16

Due to the rise of graphics and AI applications that require a narrower floating-point type, 16-bit float formats like IEEE-754 binary16 and Google's bfloat16 are also introduced to in many platforms and compilers also have some limited support for them, like __fp16 in GCC

这篇关于C ++编译器中存在哪些不常见的浮点大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 18:37