When to use Fixed Point these days

前端 未结 7 2441
生来不讨喜
生来不讨喜 2021-02-18 13:25

For intense number-crunching i\'m considering using fixed point instead of floating point. Of course it\'ll matter how many bytes the fixed point type is in size, on what CPU i

相关标签:
7条回答
  • 2021-02-18 13:58

    Use fixed-point when the hardware doesn't support floating-point or the hardware implementation sucks.

    Also beware when making classes for it. Something you think would be quick could actually turn out to be a dog when it comes to profiling due to (un)necessary copies of classes. That is another question for another time however.

    0 讨论(0)
  • 2021-02-18 14:01

    Its nearly ALWAYS faster to use fixed point (experience of x86, pentium, 68k and ARM). It can, though, also depend on the application type. For graphics programming (one of my main uses of fixed point) I've been able to optimize the code using prebuilt cosine tables, log tables etc. But also the basic mathematical operations have also proven faster.

    A comment on financial software. It was said in an earlier answer that fixed point is useful for financial calculations. In my own experience (development of large treasury management system and extensive experience of credit card processing) I would NOT use fixed point. You will have rounding errors using either floating or fixed point. We always use whole amounts to represent monetary amounts, counting the minimum amount possible (1c for Euro or dollar). This ensure no partial amounts are ever lost. When doing complex calculations values are converted to doubles, application specific rounding rules are applied and results are converted back to whole numbers.

    0 讨论(0)
  • 2021-02-18 14:05

    Since you are using a general-purpose CPU, I would suggest not using fixed point, unless performance is so critical for your application that you have to count every tic. The hassle of implementing fixed point, and dealing with issues like overflow is just not worth it, when you have a CPU, which will do it for you.

    IMHO, fixed point is only necessary when you are using a DSP without hardware support for floating point operations.

    0 讨论(0)
  • 2021-02-18 14:07

    Another good reason to use fixed decimal is that rounding is much simpler and predictable. Most of the financial software uses fixed point arbitrary precision decimals with half-even rounding to represent money.

    0 讨论(0)
  • 2021-02-18 14:15

    In situations where you are dealing with very large amounts of data, fixed point can be twice as memory efficient, e.g. a four byte long integer as opposed to an eight byte double. A technique often used in large geospatial datasets is to reduce all the data to a common origin, such that the most significant bits can be disposed of, and work with fixed point integers for the rest. Floating point is only important if the point does actually float, i.e. you are dealing with a very wide range of numbers at very high accuracy.

    0 讨论(0)
  • 2021-02-18 14:15

    Another reason to use fixed-point is that ARM devices, like mobile phones and tablets, lack of FPU (at least many of them).

    For developing real-time applications it makes sense to optimize functions using fixed-point arithmetic. There are implementations of FFTs (Fast Fourier Transform), very importan for graphics, that base its improvements on efficiency on relying on floating point arithmetic.

    0 讨论(0)
提交回复
热议问题