Go to the first, previous, next, last section, table of contents.

Reentrancy Properties of libm

When a math function detects an error, it sets the static variable errno. Depending upon the severity of the error, it may also print a message to stderr. None of this behavior is reentrant. When one process detects an error, it sets errno. If another process is testing errno, it detects the change and probably fails. Note that failing system calls can also set errno. This problem can only be fixed by either ignoring errno, or treating it as part of the context of a process and switching it along with the rest of a processor state. In normal debugged programs, there are usually no math subroutine errors--and therefore no matherr calls; in that situation, the math functions behave reentrantly.

As an alternative, you can use the reentrant versions of the mathematical functions: these versions have a different name, normally formed by prepending `_' and appending `_r', and use an extra argument--a pointer to the particular reentrancy structure to use. See section `Reentrancy' in The Cygnus C Support Library, for more discussion of this approach to reentrancy.

The reentrancy structure is always an additional first argument; for example, the reentrant version of `double acos (double x)' is `double _acos_r (void *reent, double x)'.

Here is a list of the names for reentrant versions of the mathematical library functions:

_acos_r            _gammaf_r_r           _log10f_r   
_acosf_r           _hypot_r              _log_r      
_acosh_r           _hypotf_r             _logf_r     
_acoshf_r          _j0_r                 _pow_r      
_asin_r            _j0f_r                _powf_r     
_asinf_r           _j1_r                 _remainder_r
_atanh_r           _j1f_r                _sinh_r     
_atanhf_r          _jn_r                 _sinhf_r    
_cosh_r            _jnf_r                _sqrt_r     
_coshf_r           _ldexp_r              _sqrtf_r    
_exp_r             _ldexpf_r             _y0_r       
_expf_r            _lgamma_r             _y0f_r      
_fmod_r            _lgamma_r_r           _y1_r       
_fmodf_r           _lgammaf_r            _y1f_r      
_gamma_r           _lgammaf_r_r          _yn_r       
_gamma_r_r         _log10_r              _ynf_r      
_gammaf_r


Go to the first, previous, next, last section, table of contents.