浮点和定点表示的优缺点 [英] Advantages and disadvantages of floating point and fixed point representations

查看:3219
本文介绍了浮点和定点表示的优缺点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在过去三天一直在努力去理解浮点和定点表示之间的确切区别。我很困惑阅读材料,我无法决定什么是对的,什么是错的。其中一个问题是精确,尾数,非标准化,下溢等技术术语的含义。

任何人都可以用例子给出分歧吗?

到目前为止,并能够清楚地理解)如下所示: - $ /

浮点数 -

1. 优势提供非常大的范围

2. 缺点四舍五入大号



定点 -

1. 优势 完全代表 (涉及金钱时使用)

2. 缺点提供一个非常有限的范围



但是我知道有更多的差异(主要优点和缺点)。任何人都可以列出解释吗?

解决方案

浮点技术需要花费很多时间才能适应。简单地说,浮点实现了一个高域(从非常小的数字接近零到非常高的数字,有时甚至高于宇宙中的原子数)。通过保持相对错误不变,浮点实现了这一点。即该数字将在固定小数位数后开始舍入(这是一种简化,但有助于理解原理)。这与大多数自然科学的重要人物概念非常相似。但是这意味着浮点数总是以某种方式舍入。如果你添加一个非常小的数字到一个非常大的数字,小号码将被截断,大号码将保持。当小数字低于阈值时会发生这种情况。如果添加很多数字,有时可能需要先排序,然后在大数字之前添加小数字。还有数值稳定性的概念要考虑,即一个算法如何由于四舍五入而从正确的结果中漂移。另一方面,定点表示将始终具有相同的绝对错误。如果您存储4位小数的货币,则您知道您的数据将被关闭,最多为.00005美分。如果你添加你的数据,这个错误可能会再次累积,但是这个规则与浮点规则有很大的不同。



除非你是沉重的责任数字工作,这些问题可能不应该被考虑。大多数情况下,浮点数和定点数都可以正常工作,但要小心谨慎(即不要在浮点数或定点数上使用 == 两种方式来比较它们是不同的)。此外,AFAIK浮标在科学工作中更经常使用,因为大多数情况下,科学家将接受数值训练,知道如何处理舍入,只对相对精确的结果感兴趣。固定点用于财务,每个舍入必须被计入并存储在某个地方(通常银行会保留半个圆形的小数),所以您必须对绝对误差进行很好的控制,以便以后能够考虑它。


I have been trying for the last three days to understand the exact differences between floating and fixed point representations. I am confused reading the material and I'm unable to decide what is right and what is wrong.

One of the problems is with the meaning of few technical terms like 'precision', 'mantissa', 'denormalised', 'underflows' etcetera.

Can anyone give the differences with examples?

The points I have been able to find out until now (and able to understand clearly) are as follows :-

Floating point -
1. Advantage Provides a very large range
2. Disadvantage Rounds off large numbers

Fixed point -
1. Advantage Numbers are represented exactly (Used when 'money' is involved)
2. Disadvantage Provide a very limited range

But I know there are a lot more differences (Advantages and disadvantages mainly). Can anyone list them out with explanations?

解决方案

The technalities behind floating point take a lot of time to get used to. I will not go into detail here.

Simply stated, floating points achieve a high domain (from very small numbers close to zero to very high numbers, sometimes even higher than the number of atoms in the universe). Floating points achieve this by keeping the relative error constant. I.e. the number will start to be rounded after an fixed number of decimals (this is a simplification, but helps to understand the principle). This is very similar to the concept of "significant figures" from most natural sciences. However this means that floating point numbers are always somehow rounded. If you add a very small number to a very big number, the small number will just be truncated and the big number will stay. This happens when the small number is below the the threshold. If you add many numbers it might sometimes be necessary to sort them first and adding the small ones before the big ones. There is also the concept of numeric stability to consider, i.e. how an algorithm will drift of from the correct result due to the rounding.

Fixed point representation on the other hand will always have the same absolute error. If you store currency with 4 decimal places, you know your data will be off by a maximum of .00005 cent. If you add your data however, this error again might accumulate, but the rules for this are a lot different from the rules for floating points.

Unless you are duing heavy duty numeric work, these problems probably should not be considered. Most of the times floating point numbers and fixed point numbers work just fine, when good care is taken (i.e. never use == on floating point numbers or fixed point numbers. The correct way to compare them however is differnt for both). Also AFAIK floats are used more often in scientific work, because most often the scientists will have training in numerics, know how to deal with rounding and are only interested in relatively exact results. Fixed points are used in finances, where each rounding has to be accounted and stored somewhere (often the banks will just keep the rounded half microcents), so you have to have a very good controll of the absolute error to be later able to account for it.

这篇关于浮点和定点表示的优缺点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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