为什么IEEE754单precision浮动只有7位precision? [英] Why IEEE754 single-precision float has only 7 digit precision?

查看:264
本文介绍了为什么IEEE754单precision浮动只有7位precision?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么一个单precision浮点数有7位precision(或双位数15-16 precision)?

Why does a single-precision floating point number have 7 digit precision (or double 15-16 digits precision)?

任何人能请解释一下我们是如何在这基础上分配给浮动的32位到达(符号(32)指数(30-23),分数(22-0))?

Can anyone please explain how we arrive on that based on the 32 bits assigned for float(Sign(32) Exponent(30-23), Fraction (22-0))?

推荐答案

23分的有效数位(22-0)出现在内存格式,但总precision实际上是24位的,因为我们假设有一领先1。这相当于日志10(2 ^ 24)≈7.225 十进制数字。

23 fraction bits (22-0) of the significand appear in the memory format but the total precision is actually 24 bits since we assume there is a leading 1. This is equivalent to log10(2^24) ≈ 7.225 decimal digits.

双精度型$ P ​​$ pcision浮有52位分数,再加上领先1 53.因此,一个双能容纳日志10(2 ^ 53)≈15.955 十进制数字,不太16。

Double-precision float has 52 bits in fraction, plus the leading 1 is 53. Therefore a double can hold log10(2^53) ≈ 15.955 decimal digits, not quite 16.

注:1领先的是不是一个符号位。它实际上是( - 1)^ *号1.ffffffff * 2 ^(EEEE常数),但我们不必存储领先1的比例。符号位仍然必须保存

Note: The leading 1 is not a sign bit. It is actually (-1)^sign * 1.ffffffff * 2^(eeee-constant) but we need not store the leading 1 in the fraction. The sign bit must still be stored

有不能被重新psented为2的乘方的总和$ P $一些数字,如1/9:

There are some numbers that cannot be represented as a sum of powers of 2, such as 1/9:

>>>> double d = 0.111111111111111;
>>>> System.out.println(d + "\n" + d*10);
0.111111111111111
1.1111111111111098

如果一个财经节目要做到这一点计算一遍又一遍没有自我修正,但最终将差异。

If a financial program were to do this calculation over and over without self-correcting, there would eventually be discrepancies.

>>>> double d = 0.111111111111111;
>>>> double sum = 0;
>>>> for(int i=0; i<1000000000; i++) {sum+=d;}
>>>> System.out.println(sum);
111111108.91914201

在1十亿求和,我们缺少了$ 2

After 1 billion summations, we are missing over $2.

这篇关于为什么IEEE754单precision浮动只有7位precision?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆