Intro -- introduction to math library routines


cc . . . -lm

#include <math.h>


This section contains manual pages for the routines in the libm math library. See math(5) for declarations of functions and constants. In addition, see tgmath(5) for definitions of several type-generic macros.

This library is implemented as a shared object,, and an archive, libm.a. It is not automatically linked by the C compilation system. Specify -lm on the cc(1) command line to link with the shared object version of the library. Specify -dn -lm on the cc(1) command line to link with the archive version of this library and the archive version of all other libraries being searched.


LIBDIR/ libm library (shared object)

LIBDIR/libm.a libm library (archive)

Return values

For functions that return a floating-point value, if an error occurs, the value of errno will be one of the values represented by the manifest constants EDOM or ERANGE (defined in math.h). EDOM typically indicates a domain error: one of the input values was not in the domain of the function. ERANGE typically indicates a range error: the calculated result was either too big or too small to be represented by the data type returned by the function.

Functions that result in a range error typically return zero for underflow or, for overflow, a value that compares equal to ±HUGE_VAL, ±HUGE_VALF or ±HUGE_VALL according to the function's precision. HUGE_VAL, HUGE_VALF and HUGE_VALL are defined in math.h. On systems that support IEEE infinity, HUGE_VAL is infinity.

If the system supports IEEE NaN (not-a-number), functions that result in a domain error typically return NaN. Such functions may also raise one of the IEEE floating-point exceptions. On systems that do not support IEEE NaN, functions that result in a domain error typically return zero.

The error behavior for programs compiled with the -Xt (transitional) compilation mode is different (see cc(1)). In that case, these functions typically return zero instead of IEEE NaN for domain errors and a value that will compare equal to ±HUGE instead of ±HUGE_VAL for overflows. HUGE is defined in math.h. For more information, see matherr(3M).


A character (except a multibyte character; see mbchar(3C)) is any bit pattern able to fit into a byte on the machine. The null character is a character with value 0, conventionally represented in the C language as \0. A character array is a sequence of characters. A null-terminated character array (a ``string'') is a sequence of characters, the last of which is the null character. The null string is a character array containing only the terminating null character. A NULL pointer is the value that is obtained by casting 0 into a pointer. C guarantees that this value will not match that of any legitimate pointer, so many functions that return pointers return NULL to indicate an error. The macro NULL is defined in stdio.h. Types of the form size_t are defined in the appropriate header files.



Standards comformance

The 3M functions conform to, and include all the math.h functions specified in the 1989 and 1999 C standards as well as both the Open Group UNIX 95 and UNIX 98 specifications.
© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004