双精度值无法正确表示哪些值 [英] Which values cannot be represented correctly by a double

查看:154
本文介绍了双精度值无法正确表示哪些值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Double数据类型无法正确表示某些10位值。这是因为浮点数代表实数。这意味着,当表示货币值时,应该使用十进制值类型来防止错误。 (请随意纠正此前言中的错误)

The Double data type cannot correctly represent some base 10 values. This is because of how floating point numbers represent real numbers. What this means is that when representing monetary values, one should use the decimal value type to prevent errors. (feel free to correct errors in this preamble)

我想知道什么是在64位下的Double数据类型下呈现这样的问题的值架构在标准的.Net框架(C#,如果这有所作为)?

What I want to know is what are the values which present such a problem under the Double data-type under a 64 bit architecture in the standard .Net framework (C# if that makes a difference) ?

我希望答案是一个公式或规则来找到这样的值,但我也想要一些示例值。

I expect the answer the be a formula or rule to find such values but I would also like some example values.

推荐答案

任何不能写为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.

这篇关于双精度值无法正确表示哪些值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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