There are mathematical operations that yield real numbers from +/- infinity. For example exp(-infinity) = 0. Is there a standard for mathematical functions in the standard C library that accept IEEE-754 infinities (without throwing, or returning NaN). I am on a linux system and would be interested in such a list for glibc. I could not find such a list in their online manual. For instance their documentation on exp does not mention how it handles the -infinity case. Any help will be much appreciated.
27
votes
2 Answers
13
votes
The See Also section of POSIX' math.h definition links to the POSIX definitions of acceptable domains.
E.g. fabs():
If x is ±0, +0 shall be returned.
If x is ±Inf, +Inf shall be returned.
I converted mentioned See Also-section to StackOverflow-Markdown:
acos(), acosh(), asin(), atan(), atan2(), cbrt(), ceil(), cos(), cosh(), erf(), exp(), expm1(), fabs(), floor(), fmod(), frexp(), hypot(), ilogb(), isnan(), j0(), ldexp(), lgamma(), log(), log10(), log1p(), logb(), modf(), nextafter(), pow(), remainder(), rint(), scalb(), sin(), sinh(), sqrt(), tan(), tanh(), y0(),
I contributed search/replace/regex-fu. We now just need someone with cURL-fu.
exp(-infinity)? Did it throw? Did it get NaN or 0? - Anders Abelexpguarantees +0 for -Inf. - Matstd::numeric_limits<double>::is_iec559yieldstrue, then the intended meaning is that you can assume both representation and semantics. But in practice you can only assume the representation (e.g. consider g++ option--fastmath, IIRC). So as @KerrekSB notes, you'll have to check the implementation's documentation. Or just try out things. Cheers & hth., - Cheers and hth. - Alf