[英]Invertability of IEEE 754 floating-point division
What is the invertability of the IEEE 754 floating-point division? IEEE 754浮点除法的可逆性是什么? I mean is it guaranteed by the standard that if
double y = 1.0 / x
then x == 1.0 / y
, ie x
can be restored precisely bit by bit? 我的意思是标准保证如果
double y = 1.0 / x
然后x == 1.0 / y
,即x
可以精确地逐位恢复?
The cases when y
is infinity
or NaN
are obvious exceptions. 当
y
是infinity
或NaN
时的情况是明显的例外。
Yes, there are IEEE 754 double-precision(*) values x
that are such x != 1.0 / (1.0 / x)
. 是的,IEEE 754双精度(*)值
x
是x != 1.0 / (1.0 / x)
。
It is easy to build an example of a normal value with this property by hand: the one that's written 0x1.fffffffffffffp0
in C99's hexadecimal notation for floating-point values is such that 1.0 / (1.0 / 0x1.fffffffffffffp0) == 0x1.ffffffffffffep0
. 手动使用此属性很容易构建一个正常值的示例:在C99的浮点值的十六进制表示法中写入
0x1.fffffffffffffp0
的那个是1.0 / (1.0 / 0x1.fffffffffffffp0) == 0x1.ffffffffffffep0
。 It was natural to expect 0x1.fffffffffffffp0
to be a counter-example because 1.0 / 0x1.fffffffffffffp0
falls at the beginning of a binade, where floating-point numbers are less dense, so a larger relative error had to happen on the innermost division. 很自然地期望
0x1.fffffffffffffp0
是一个反例,因为1.0 / 0x1.fffffffffffffp0
落在一个binade的开头,浮点数密度较小,所以最内部的分支必须发生较大的相对误差。 More precisely, 1.0 / 0x1.fffffffffffffp0
falls just above the midpoint between 0.5
and its double-precision successor, so that 1.0 / 0x1.fffffffffffffp0
is rounded up to the successor of 0.5, with a large relative error. 更确切地说,
1.0 / 0x1.fffffffffffffp0
恰好位于0.5
和它的双精度后继之间的中点之上,因此1.0 / 0x1.fffffffffffffp0
向上舍入到0.5的后继,具有较大的相对误差。
In decimal %.16e
format, 0x1.fffffffffffffp0
is 1.9999999999999998e+00
and 0x1.ffffffffffffep0
is 1.9999999999999996e+00
. 在十进制
%.16e
格式中, 0x1.fffffffffffffp0
是1.9999999999999998e+00
和0x1.ffffffffffffep0
是1.9999999999999996e+00
。
(*) there is no reason for the inverse function to have the property in the question for any of the IEEE 754 format (*)反函数没有理由在任何IEEE 754格式的问题中具有属性
Obviously not. 显然不是。 1/10 has no representation.
1/10没有代表。 You get an approximation instead.
你会得到一个近似值。 Inverting that will not give you 10.
颠倒那不会给你10。
Edit: there are a large number of these. 编辑:有很多这些。 Any inverse that requires more than 53 bits will be one of them.
任何需要超过53位的反转都将是其中之一。
There is an easy test. 有一个简单的测试。 In C you could test 1.0/(1.0/10.0) against 10.0 and you will discover they aren't equal.
在C中你可以测试1.0 /(1.0 / 10.0)对10.0,你会发现它们不相等。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.