Practices to limit floating point accuracy problems

后端 未结 2 1739
执笔经年
执笔经年 2021-01-22 10:24

As programmers, most (if not all of us) know that floating point numbers have a tendency to not be very accurate. I know that this problem can\'t be avoided entirely, but I am w

2条回答
  •  时光说笑
    2021-01-22 10:42

    Use fixed-point mathematics where you can deal with a known limited precision.

    As an example, the Rockbox music player firmware uses almost entirely fixed-point media codecs.

    If you must be perfectly accurate, use an infinite-length storage type like those provided by the GMP library.

    If you're just trying to cut down on your errors, try to work as close to zero as possible, where the IEEE FP numbers are more precise. Reorder your operations to avoid letting your absolute values get too large.

提交回复
热议问题