intro(3M) (Math Libraries) intro(3M)
NAME
intro - introduction to math libraries
SYNOPSIS
cc [flag ...] file ... -lm [library ...]
cc -O -Ksd [flag ...] file ... -J sfm [library ...]
#include <math.h>
DESCRIPTION
This section describes the functions in the math libraries, libm and
libsfm. Declarations for these functions may be obtained from the
#include file math.h. Several generally useful mathematical
constants are also defined there [see intro(3) and math(5)].
Some of the AT&T 3B2 SVR4 documentation set guides include duplicates
of relevant manpages. In this documentation set, all manpages may be
found in the appropriate Reference Manual and, with the exception of
the Programmer's Guide: XWIN Graphical Windowing System, the
Programmer's Guide: OPEN LOOK Graphical User Interface, and the OPEN
LOOK Graphical User Interface User's Guide, are never duplicated in
the guides.
The Reference Manual pages are divided as follows: User's Reference
Manual: Section 1 and all subsections (except 1M). System
Administrator's Reference Manual: Sections 1M, 7 and 8. Programmer's
Reference Manual: Section 2 through 6.
The math libraries are not automatically loaded by the C compilation
system; use the -l or -J options to cc to access the libraries as
follows:
-lm Search the regular math library, libm.
-J sfm Do in-line expansion of functions from the fast
single-precision assembly source math library,
libsfm. Specify -O -Ksd to optimize for speed.
libm Contains the full set of double-precision routines plus some
single-precision routines (designated by the suffix f) that
give better performance with less precision. Selected
routines are hand-optimized for performance. The optimized
routines include sin, cos, tan, atan, atan2, exp, log, log10,
pow, and sqrt and their single-precision equivalents.
libsfm Contains the functions sinf, cosf, tanf, asinf, acosf, atanf,
expf, logf, log10f, powf, and sqrtf. The source library
routines are in-line expanded by the optimizer to provide
faster execution by reducing the overhead of argument
passing, function calling and returning, and return value
7/91 Page 1
intro(3M) (Math Libraries) intro(3M)
passing. The source library is designed for applications
that desire an increase in speed at the potential cost of
size.
libsfm should be used only when necessary and with extreme
caution. It is a special purpose library that does not do
error checking or domain reduction. In other words, these
functions never call matherr, and arguments aren't reduced to
be within a finite range.
Inputs to sinf andπcosf must be in the range
π < x < 2
Inputs t-
o tanf mus-
n
t be in the range
π < x < 2
Inputs t-
o sqrtf, logf, and log10f must be greater than 0.
DEFINITIONS
See intro(3) for C language definitions.
FILES
LIBDIR usually /usr/ccs/lib
LIBDIR/libm.a
SEE ALSO
cc(1), intro(2), intro(3), math(5).
The ``Floating Point Operations'' chapter in the Programmer's Guide:
ANSI C and Programming Support Tools.
DIAGNOSTICS
Error handling varies according to compilation mode. Under the -Xt
(default) option to cc, these functions return the conventional
values 0, +HUGE, or NaN when the function is undefined for the given
arguments or when the value is not representable. In the -Xa and -Xc
compilation modes, +HUGE_VAL is returned instead of +HUGE. (HUGE_VAL
and HUGE are defined in math.h to be infinity and the largest-
magnitude single-precision number, respectively.) In every case, the
external variable errno [see intro(2)] is set to the value EDOM or
ERANGE, although the value may vary for a given error depending on
compilation mode. See the table under matherr(3M) below.
Page 2 7/91