c++ primer 4th edition:
The types float, double, and long double represent floating-point single-, double-, and extended-precision values. Typically, floats are represented in one word (32 bits), doubles in two words (64 bits), and long double in either three or four words (96 or 128 bits). The size of the type determines the number of significant digits a floating-point value might contain.
根据Intel的文档的描述,双精度浮点的精度是53位,去掉1位,还有52位,总共还有12位可以给符号位以及指数位使用,符号位占据1位,剩下11位给指数位使用。而范围则是从2^(-1022)到2^(1023),换算成十进制,是2.23*10^(-308)到1.79*10^(308)
而long double本来的长度是80位,有效精度64位(实际63位),15位指数位,加上1符号位,中间还要加上一个integer bit(Intel的文档里面这么描述的),范围是2^(-16382)到2^(16383),十进制的为3.37*10(-4932)到1.18*10^(4932)。
楼主所说的问题不在于机器,而在于编译器,VC和GCC里面的long double和double其实是一样的,如果真的需要使用long double,应该要用汇编了:)
补充:汇编用long double不是说它的语法,是因为可以直接操作到80bit的寄存器,自然就可以存储long double类型的数据,如果楼主只是需要一个80bitlong double型的话可以看看这个:
http://www.codeproject.com/csharp/LongDouble.asp这里提供了一个例子,简介如下:
Abstract
I recently found myself needing to read Intel 80-bit long doubles from a binary stream whilst integrating with another system. For cross platform compatibility reasons, Microsoft decided not to include a long double (a.k.a. extended) type in the framework and thus I was forced to interpret the bytes myself.
This is not an implementation of a long double type, but a BitConverter class that translates between long double byte arrays and regular doubles. Naturally, a certain amount of range and precision is lost during the process; however, for my purposes, this is acceptable.
Introduction
A long double is a floating point number that is 16 bits bigger than a regular double. These additional bits are used to increase both the range and precision of the number and are usually used for mathematical and scientific calculations.
This article describes how to read a long double byte array and create a regular double value from it. The inverse operation is simply a matter of reversing the procedure and will not be covered here.