Advantages and disadvantages of floating point and fixed point representations [closed]

非 Y 不嫁゛ 提交于 2019-12-09 07:23:12

问题


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?


回答1:


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.




回答2:


Floating point numbers are good for, well, floating points, i.e. when you need to express numbers across varying scales. You sacrifice precision to gain range of scale.

On the other hand, fixed point numbers are only suitable at a fixed scale (and they'll over- or underrun if you scale them too much), but you gain precision as long as you remain within the desired scale.

In short: If you multiply a lot but don't add numbers of different scales, use floating points. If you add a lot but don't multiply, use fixed points.

(A good example of a fixed-point use case is anything relating with currency: Essentially, you can fix your unit to be cents, or one hundredth of a cent, and make all your monetary values be integers in that unit.)




回答3:


Fixed pointed numbers can be sorted in linear time. Fixed point is also unambiguous; each numerical value that can be expressed in specific fixed point protocol has only one representation, which isn't true with floating point.

Floating point has a much wider representable range. It is also ambiguous. Floating point numbers can be sorted in NlogN time.




回答4:


Fixed point is a representation of floating point number in integer format. So operations can be applied on the number just like on integers. The advantage of using this is that floating point arithmetic is costlier (processing power). Newer processors have dedicated FPUs (floating point units) for handling that.

So fixed point arithmetic is when processing power is limited, and a little precision loss doesn't cause a havoc.



来源:https://stackoverflow.com/questions/9646633/advantages-and-disadvantages-of-floating-point-and-fixed-point-representations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!