3 ms·
It's unusual, outside x86, for these functions to be hardware accelerated. So just about every libm has to do it in software. Nearly all libm implementations a
by fargle 3y ago
It's unusual, outside x86, for these functions to be hardware accelerated. So just about every libm has to do it in software.
Nearly all libm implementations around are based off Sun's fdlibm from the 80's-90's, including a bunch of the variants cited below, *bsds, etc. They are basically updated slightly, but you can see their heritage in the structure of the code. The original is found on netlib these days: https://www.netlib.org/fdlibm/k_cos.c https://www.netlib.org/fdlibm/k_cos.c
14th order polynomial, but only uses ~7 terms. It's supposed to have error < 1 ULP. For fdlibm, it's pretty readable compared to some of the other fun ones. I seem to remember sqrt being a bit gnarly.