27
votes

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.

2
Have you tried exp(-infinity)? Did it throw? Did it get NaN or 0? - Anders Abel
+1 even just for the title :-) - Matteo Italia
The language standard does not say anything about whether infinity is a representable value, so surely this is up to the implementation. - Kerrek SB
@srean: POSIX exp guarantees +0 for -Inf. - Mat
¤ There are two aspects to IEEE 754: binary representation, and semantics. If std::numeric_limits<double>::is_iec559 yields true, 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

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.

9
votes

In C99 it's on Appendix F:

F.9.3.1 The exp functions
-- exp(±0) returns 1.
-- exp(-∞) returns +0.
-- exp(+∞) returns +∞.

Appendix F is normative and:

An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.