且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

双精度值无法正确表示哪些值

更新时间:2022-11-01 10:42:09

任何不能写为2和正负的和的总和的数字不能精确地表示为二进制浮点数,点数。

Any number which cannot be written as the sum of positive and negative powers of 2 cannot be exactly represented as a binary floating-point number.

常见的 IEEE格式的 32 - 和浮点数的64位表示进一步约束;它们限制有效位数和指数中的二进制数位数。所以有最大和最小可表示的数字(大约+/- 10 ^ 308(基于-10),如果内存),并限制可以表示的数字的精度。对于精度的这个限制意味着,对于64位数字,最大功率2的指数与数字中的最小功率之间的差异被限制为52,所以如果你的数字包含2 ^ 52的项,它可以不包括2 ^ -1的术语。

The common IEEE formats for 32- and 64-bit representations of floating-point numbers impose further constraints; they limit the number of binary digits in both the significand and the exponent. So there are maximum and minimum representable numbers (approximately +/- 10^308 (base-10) if memory serves) and limits to the precision of a number that can be represented. This limit on the precision means that, for 64-bit numbers, the difference between the exponent of the largest power of 2 and the smallest power in a number is limited to 52, so if your number includes a term in 2^52 it can't also include a term in 2^-1.

二进制浮点数不能正确表示的数字的简单示例包括 1 / 3 2/3 1/5

Simple examples of numbers which cannot be exactly represented in binary floating-point numbers include 1/3, 2/3, 1/5.

由于一组浮点数(在任何表示中)都是有限的,并且实数集是无限的,所以一个算法找到一个不能精确表示为浮点数的实数,点数是随机选择一个实数。实数可以作为浮点数确定的概率为 0

Since the set of floating-point numbers (in any representation) is finite, and the set of real numbers is infinite, one algorithm to find a real number which is not exactly representable as a floating-point number is to select a real number at random. The probability that the real number is exactly representable as a floating-point number is 0.