精度Vs的含义。双重类型范围 [英] Meaning of Precision Vs. Range of Double Types

查看:114
本文介绍了精度Vs的含义。双重类型范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

首先,请允许我承认我是一位经验丰富的程序员,他拥有超过10年的编程经验。但是,我要问的问题是一个问题,此后一直困扰着我,大约十年前我第一次拿起有关C的书。

To begin with, allow me to confess that I'm an experienced programmer, who has over 10 years of programming experience. However, the question I'm asking here is the one, which has bugged me ever since, I first picked up a book on C about a decade back.

下面是摘自一本关于Python的书的摘录,解释了Python Floating类型。

Below is an excerpt from a book on Python, explaining about Python Floating type.


浮点数使用本地浮点数的
双精度(64位)表示形式
机器。通常,这是IEEE 754,它提供大约
17位的精度,并且指数在–308到
308之间。这与C语言中的double类型相同。

Floating-point numbers are represented using the native double-precision (64-bit) representation of floating-point numbers on the machine. Normally this is IEEE 754, which provides approximately 17 digits of precision and an exponent in the range of –308 to 308.This is the same as the double type in C.

我从不了解短语的意思


...大约提供17位数字的精度,并且
的指数在–308到308之间...

" ... which provides approximately 17 digits of precision and an exponent in the range of –308 to 308 ... "



<我的直觉误入歧途,因为我可以理解精度的含义,但是范围又有何不同。我的意思是,如果浮点数最多可以表示17个数字(即最大1,000,000,000,000,000,00-1),那么指数如何为+308。如果指数是10,那不是308个数字,如果指数是2,不是100个数字。

My intuition here goes astray, since i can understand the meaning of precision, but how can range be different from that. I mean, if a floating point number can represent a value up to 17 digits, (i.e. max of 1,000,000,000,000,000,00 - 1), then how can exponent be +308. wouldn't that make a 308 digit number if exponent is 10 or a rough 100 digit number if exponent is 2.

我希望,我能表达我的困惑。

I hope, I'm able to express my confusion.

关于
Vaid,Abhishek

Regards Vaid, Abhishek

推荐答案

我们用两位数的精度写1500。这意味着我们足够精确地将1500与1600和1400相区别,但是不够精确地将1500与1510或1490相区别。将这些数字区分开将需要三位数的精度。

Suppose that we write 1500 with two digits of precision. That means we are being precise enough to distinguish 1500 from 1600 and 1400, but not precise enough to distinguish 1500 from 1510 or 1490. Telling those numbers apart would require three digits of precision.

即使我写了四位数字,浮点表示也不一定包含所有这些数字。 1500是1.5 * 10 ^ 3。用十进制浮点数表示法,精度为两位数,只存储数字的前两位和指数,我将其写为(1.5,3)。

Even though I wrote four digits, floating-point representation doesn't necessarily contain all these digits. 1500 is 1.5 * 10^3. In decimal floating-point representation, with two digits of precision, only the first two digits of the number and the exponent would be stored, which I will write (1.5, 3).

为什么实数和占位符零之间有区别?因为它告诉我们如何精确地表示数字,即由于近似值而损失了其价值的一部分。我们可以将1500 =(1.5,3)与1500 + 100 =(1.6,3)区分开。但是,如果我们增加指数,就无法将15000 =(1.5,4)与15000 + 100 =(1.51,4)区分开。充其量,我们可以用两位精度的十进制数字来近似+/- 10%之内的数字。无论指数大小是多少,都是如此。

Why is there a distinction between the "real" digits and the placeholder zeros? Because it tells us how precisely we can represent numbers, that is, what fraction of their value is lost due to approximation. We can distinguish 1500 = (1.5, 3) from 1500+100 = (1.6, 3). But if we increase the exponent, we can't distinguish 15000 = (1.5, 4) from 15000+100 = (1.51, 4). At best, we can approximate numbers within +/- 10% with two decimal digits of precision. This is true no matter how small or large the exponent is allowed to be.

这篇关于精度Vs的含义。双重类型范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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