Definitions of sqrt, sin, cos, pow etc. in cmath

后端 未结 8 1117
野趣味
野趣味 2020-12-13 00:13

Are there any definitions of functions like sqrt(), sin(), cos(), tan(), log(), exp() (these fr

8条回答
  •  有刺的猬
    2020-12-13 01:06

    Having looked a lot at math code, I would advise against looking at glibc - the code is often quite difficult to follow, and depends a lot on glibc magic. The math lib in FreeBSD is much easier to read, if somehow sometimes slower (but not by much).

    For complex functions, the main difficulty is border cases - correct nan/inf/0 handling is already difficult for real functions, but it is a nightmare for complex functions. C99 standard defines many corner cases, some functions have easily 10-20 corner cases. You can look at the annex G of the up to date C99 standard document to get an idea. There is also a difficult with long double, because its format is not standardized - in my experience, you should expect quite a few bugs with long double. Hopefully, the upcoming revised version of IEEE754 with extended precision will improve the situation.

提交回复
热议问题