关于double 和 long double 的长度
书上说:
float 是4个字节;
double 是8个字节;
long double 是三个或四个字,也就是12个字节或16个字节
但是:
# include<stdio.h>
main()
{
long double i;
printf("%d\n",sizeof(i));
return;
}
结果是8. 是2个字,不是三个或四个字.
[解决办法]
Type long double
The range of values for a variable is bounded by the minimum and maximum values that can be represented internally in a given number of bits. However, because of C’s conversion rules (discussed in detail in Type Conversions in Chapter 4) you cannot always use the maximum or minimum value for a constant of a particular type in an expression.
For example, the constant expression -32768 consists of the arithmetic negation operator (–) applied to the constant value 32,768. Since 32,768 is too large to represent as a short int, it is given the long type. Consequently, the constant expression -32768 has long type. You can only represent –32,768 as a short int by type-casting it to the short type. No information is lost in the type cast, since –32,768 can be represented internally in 2 bytes.
The value 65,000 in decimal notation is considered a signed constant. It is given the long type because 65,000 does not fit into a short. A value such as 65,000 can only be represented as an unsigned short by type-casting the value to unsigned short type, by giving the value in octal or hexadecimal notation, or by specifying it as 65000U. You can cast this long value to the unsigned short type without loss of information, since 65,000 can fit in 2 bytes when it is stored as an unsigned number.
Microsoft Specific —>
The long double contains 80 bits: 1 for sign, 15 for exponent, and 64 for mantissa. Its range is +/–1.2E4932 with at least 19 digits of precision. Although long double and double are separate types, the representation of long double and double is identical.
END Microsoft Specific
[解决办法]
char, unsigned char, signed char
1 byte
short, unsigned short
2 bytes
int, unsigned int
4 bytes
long, unsigned long
4 bytes
float
4 bytes
double
8 bytes
long double
8 bytes
是哪个混账的书说的!
[解决办法]
因为VS没有遵循标准,至少2008下还是和double一样,
[解决办法]
Previous 16-bit versions of Microsoft C/C++ and Microsoft Visual C++ supported the long double, 80-bit precision data type. In Win32 programming, however, the long double data type maps to the double, 64-bit precision data type. The Microsoft run-time library provides long double versions of the math functions only for backward compatibility. The long double function prototypes are identical to the prototypes for their double counterparts, except that the longdouble data type replaces the double data type. The long double versions of these functions should not be used in new code.
这是vs2008的msdn上的
[解决办法]