开发者

Floating point in or out of range?

Both of these examples below have 8 significand digits, but the first case doesn't give any warning, while the second case does, why?

float f1 =开发者_JAVA百科 11111111;
float f2 = 99999999;

Does the float data type have 7 or 8 significand digits?


Check out this article: The IEEE754 32-bit float has a 24-bit mantissa (cue the omitted leading 1). Now 224 is 16'777'216. That means that your first number, 11'111'111, fits nicely, but the second doesn't.

Unfortunately binary isn't the same as decimal, so when discussing precision, most of the time we're really talking about binary digits, and the float has 24 significant ones. (There's a shorthand for "binary digit" that escapes me.) The conversion is log210, which is about 3.32, so you get "7.22 decimal digits" out.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜