问题描述
这是否意味着这个过程计算出来的数字可以相加,也可以相乘2倍,一个精确的二进制/浮点表示,没有舍入错误?
const dv2 =(num,limit)=> {
limit--;
if(limit === 0){
return;
} else {
console.log(num,limit);
dv2((num / 2),limit)
}
};
是否可以确定浮点数是精确还是近似值?是的,只要你使用的是二进制浮点数(例如非常常见的IEEE-754二进制浮点数),而不要使用二进制浮点数溢出到无限或下溢到低于正常的数字。在二进制浮点中,乘以或除以二是精确的,直到达到指数限制。
对于32位IEEE-754二进制,有限的正常值上升到2 -2 和到。 (有正低值正常值低至2 -149,但是它们的有效位数小于正常位数,因此精度会降低。)
对于64位IEEE-754二进制,有限正常值上升到2 1024到971,然后下降到2 - 1022 。 (有正的低于正常值的低至2 -1074)。
没有办法(没有上下文)点数正好表示或仅接近某个先前的数字。 (有一种方法可以检测浮点运算何时舍入结果,在编程语言的实现中往往忽略访问这些附加信息)。一旦一个数字被转换为一个浮点数,浮点数就是它代表什么。它不包含以前发生的舍入错误数量的信息。 (如果您还有其他关于之前的号码的信息,例如它来自一个有五位有效数字的十进制数字,那么您可能会推断出有关原始号码的事情。)
http://floating-point-gui.de/formats/binary/
Does this mean that the numbers calculated by this process can all be added to each other or multiplied by 2 any number of times and still have an exact binary/floating point representation with no rounding errors?
const dv2 = (num, limit) => {
limit--;
if (limit === 0) {
return;
} else {
console.log(num, limit);
dv2((num / 2), limit)
}
};
Is it possible to determine when a floating point number is exact or an approximation?
Yes, as long as you are using a binary floating-point (such as the very common IEEE-754 binary floating-point) and do not overflow to infinity or underflow to subnormal numbers. In binary floating-point, multiplication or division by two is exact until the exponent limits are reached.
For 32-bit IEEE-754 binary, the finite normal values go up to 2−2 and down to 2. (There are positive subnormal values as low as 2, but they have fewer bits in their significand [fraction part] than normal numbers, so precision is reduced.)
For 64-bit IEEE-754 binary, the finite normal values go up to 2−2 and down to 2. (There are positive subnormal values as low as 2.)
There is no way (without context) to determine whether a floating-point number exactly represents or only approximates some prior number. (There is a way to detect when floating-point operations have rounded a result. Accessing this additional information is often neglected in implementations of programming languages.) Once a number is converted to a floating-point number, the floating-point number exactly represents what it represents. It contains no information about the amount of rounding error that has occurred previously. (If you have other information about the prior number, such as that it came from a decimal numeral with five significant digits, then you may be able to deduce things about the original number.)
这篇关于浮点数:我可以递归地将多个数字除以2,而不会舍入误差?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!