二进制浮点可以表示哪些类型的数字? [英] What types of numbers are representable in binary floating-point?

查看:18
本文介绍了二进制浮点可以表示哪些类型的数字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读过很多关于花车的文章,但都是不必要的.我认为我已经明白了,但我只想确定一件事:

I've read a lot about floats, but it's all unnecessarily involved. I think I've got it pretty much understood, but there's just one thing I'd like to know for sure:

我知道,1/pow(2,n) 形式的分数,其中 n 是整数,可以精确地用浮点数表示.这意味着如果我将 1/32 添加到自身 3200 万次,我将得到准确的 1,000,000.

I know that, fractions of the form 1/pow(2,n), with n an integer, can be represented exactly in floating point numbers. This means that if I add 1/32 to itself 32 million times, I would get exactly 1,000,000.

1/(32+16) 之类的呢?这是二的二乘方之和的一,这行得通吗?还是 1/32+1/16 有效?这是我感到困惑的地方,所以如果有人能为我澄清这一点,我将不胜感激.

What about something like 1/(32+16)? It's one over the sum of two powers of two, does this work? Or is it 1/32+1/16 that works? This is where I'm confused, so if anyone could clarify that for me I would appreciate it.

推荐答案

总结如下:

  • 如果分母的素数分解仅包含 2,则可以用二进制精确表示一个数字.(即分母是 2 的幂)

所以 1/(32 + 16) 不能用二进制表示,因为它的分母是 3.但是 1/32 + 1/16 = 3/32 是.

So 1/(32 + 16) is not representable in binary because it has a factor of 3 in the denominator. But 1/32 + 1/16 = 3/32 is.

也就是说,在浮点类型中表示的限制更多.例如,IEEE double 中只有 53 位尾数,因此 1/2 + 1/2^500 是不可表示的.

That said, there are more restrictions to be representable in a floating-point type. For example, you only have 53 bits of mantissa in an IEEE double so 1/2 + 1/2^500 is not representable.

因此,只要指数的范围不超过 53 次方,您就可以进行二次幂之和.

So you can do sum of powers-of-two as long as the range of the exponents doesn't span more than 53 powers.

将此推广到其他基础:

  • 如果分母的素数分解仅由 2 和 5 组成,则可以以 10 为底数精确表示.

  • A number can be exactly represented in base 10 if the prime factorization of the denominator consists of only 2's and 5's.

如果 X 的分母的素数分解只包含素数,则有理数 X 可以精确地表示为基数 NN 的因式分解中找到.

A rational number X can be exactly represented in base N if the prime factorization of the denominator of X contains only primes found in the factorization of N.

这篇关于二进制浮点可以表示哪些类型的数字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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