Math Libraries |
10 |
![]() |
For convenience, Pascal supports special Pascal header files, math_p.h and sunmath_p.h, which contain prototypes of math functions, procedures, and some useful constants. The math_p.h file refers to sunmath_p.h by an #include directive.
This chapter contains the following sections:
Contents of the Math Libraries
Altogether, there are three math libraries:
Legend:
libm Functions
Most numerical functions are available in double- and single-precision version. In general, the names of the single-precision version are formed by adding f to the names of the double-precision version.
IEEE Support Functions
This section describes the IEEE support functions, including ieee_functions(), ieee_values(), and ieeee_retrospective(). ieee_functions()
The functions described in ieee_functions(3M) provide capabilities either required by the IEEE standard or recommended in its appendix. Example:
ieee_values()
IEEE values, such as infinity, NaN, minimum and maximum positive floating-point numbers, are provided by special functions described in the ieee_values(3M) man page. Another example follows.
ieee_retrospective()
The libm function ieee_retrospective() prints to stderr information about unrequited exceptions and nonstandard IEEE modes. Pascal programs call ieee_retrospective() on exit by default.
SPARC Libraries
The libm and libsunmath libraries also contain:
Arithmetic Exceptions
An arithmetic exception arises when an attempted atomic arithmetic operation does not produce an acceptable result. The meaning of the terms "atomic" and "acceptable" may vary, depending on the context.
type exception = record |
The element kind is an integer constant that describes the type of exception that occurred, and is one of the following constants. These constants are defined in the header file.
DOMAIN |
Argument domain exception |
SING |
Argument singularity |
OVERFLOW |
Overflow range exception |
UNDERFLOW |
Underflow range exception |
TLOSS |
Total loss of significance |
PLOSS |
Partial loss of significance |
If your matherr() function returns a non-zero result, no exception message is printed, and errno is not set.
libsunmath Support for IEEE Modes and Exceptions
ieee_handler() is used primarily to establish a signal handler for a particular floating-point exception or group of exceptions.
ieee_flags() is the recommended interface to:
If an exception is raised at any time during program execution, then its flag is set, unless it is explicitly cleared. Clearing accrued exceptions is done by a call, as shown in the following Pascal program.