音乐背后的数学
By Long Luo
By Long Luo
By Long Luo
https://github.com/taschini/crlibm/blob/master/trigo_fast.c
https://pavpanchekha.com/blog/synthesize-range-reductions.html
https://github.com/uxlfoundation/oneapi-construction-kit/blob/main/doc/modules/builtins/abacus.md
https://forum.orekit.org/t/jmh-performance-benchmarks-math-vs-strictmath-vs-fastmath-hipparchus-vs-fastmath-apache/4661/20?page=3
By Long Luo
假如你知道浮点数的话,你就知道为什么了!
按照 IEEE 754 浮点数标准 制定的 浮点数运算法则, float 类型的单精度浮点数 的尾数部分有 \(23\) 位二进制数,如下图所示:
在十进制下,大致相当于 \(\log_{10}{2^{23}} = 23 \cdot \log {2} \approx 23 \times 0.301 \approx 6.9\) ,有效数字大约有 \(7\) 位。
所以当 \(x = 1000001\) 时,我们应该使用 double 类型的双精度浮点数 [^12] ,这样才能保证结果有足够的精度!
双精度浮点数的尾数部分有 \(52\) 位,如下图所示:
在十进制中大致相当于 \(\log_{10}{2^{52}} = 52 \cdot \log {2} \approx 52 \times 0.301 \approx 15.6\) ,也就是说当 \(x\) 有效数字是 \([7, 15]\) 时,我们应该使用 double 类型的双精度浮点数可以保证精度!
但这仍然有个问题,那就是 \(x\) 有效数字 超过 \(15\) 位,应该怎么办?
By Long Luo
https://github.com/maddyscientist/AlgRemez
https://erikerlandson.github.io/algorithm/libs/math/doc/html/math_toolkit/remez.html
https://abiy-tasissa.github.io/remez.pdf
https://github.com/samhocevar/lolremez