限制浮点精度问题的做法 [英] Practices to limit floating point accuracy problems
问题描述
在此先感谢。
使用可以处理已知有限精度的定点数学。例如,Rockbox音乐播放器固件使用几乎完全定点媒体编解码器。
如果您必须完全准确,使用GMP库提供的无限长存储类型。
如果你只是想减少你的错误,接近于零的地方,IEEE FP编号更精确。重新排序你的操作,以避免让你的绝对值太大。
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 wondering if there are any certain practices, patterns, etc. that can be used to at least reduce floating point errors.
Thanks in advance.
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.
这篇关于限制浮点精度问题的做法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!