| United States-English |
|
|
|
![]() |
HP-UX Floating-Point Guide: HP 9000 Computers > Chapter 4 HP-UX Math Libraries on HP 9000
SystemsContents of the HP-UX Math Libraries |
|
This section describes in some detail the contents of the math libraries. These libraries include:
The math libraries run well on both PA-RISC 1.1 and PA-RISC 2.0 systems. HP does not provide PA2.0 versions of the math libraries, although it does provide PA2.0 versions of millicode functions. See “Millicode Versions of Math Library Functions” for details. The scalar math libraries are implemented using the PA-RISC 1.1 instruction set. The most important functions are carefully optimized. For even faster performance, a number of frequently used math functions are implemented in the millicode library (/usr/lib/milli.a) as well as in the standard math library. See “Millicode Versions of Math Library Functions” for details. Several of the most frequently used math functions are implemented in the millicode library as well as in the math library. The millicode versions have a streamlined calling sequence and are usually faster than their counterparts in the math library. Millicode versions exist for the following Fortran and C functions. They have double-precision versions only, unless otherwise specified.
Millicode versions exist for the following Pascal functions:
To get the millicode versions of any of these functions, compile your program with
With the f90 and f77 compiler commands, the +Olibcalls option is the default at optimization level 2 and above. The +Olibcalls option is invoked by default when you specify the optimization type +Oaggressive; use +Oaggressive +Onolibcalls if you want aggressive optimization without using millicode routines. The millicode versions are implemented in the library /usr/lib/milli.a. The millicode versions of functions do not provide standard-conforming error handling. This has different implications for different languages. In C programs, if an error occurs, the millicode versions return the same values as their standard library counterparts, but they do not set errno. Because the C and Pascal standards specify error handling for library functions, you should use millicode versions in C and Pascal programs only if your program does not require standard-conforming error handling. The Fortran standards do not specify error handling for math intrinsic functions, so using the millicode versions has no effect on standards compliance. See “Optimizing Your Program” for more information about optimization options.
The C math library, libm, also supports
All of these functions are defined in math.h. However, all of these functions are outside the ANSI C specification, and many of them are outside the XPG4.2 specification. If you compile in strict ANSI mode (with the -Aa option), only the declarations of functions specified by the ANSI C standard are ordinarily visible to your program. Therefore, to make the additional functions visible, do one of the following:
For a complete list of the contents of libm, see Appendix A “The C Math Library”. The functions are described in online man pages. Certain libm math functions are implemented as single-precision functions, accepting float arguments and returning a float result. On HP 9000 systems, the performance of single-precision and double-precision functions is similar. If your application uses single-precision data types heavily, you may find it convenient to use the float versions of the math functions the application calls. The names of the float functions are the same as those of their double-precision counterparts but with the letter f appended. (For float versions of degree-valued trigonometric functions, the f follows the d.) This naming convention accords with that specified in Section 4.13 of the ANSI C standard, "Future Library Directions." The supplied functions are as follows:
You must compile in ANSI mode (with -Ae, the default, or with -Aa -D_HPUX_SOURCE) to use these functions. If you compile in ANSI mode, ANSI C rules are followed, and the argument is treated as a float throughout the function call. If you do not compile in ANSI mode, traditional K&R C rules are followed, the compiler generates code to promote the argument to double, and the function call either generates a linker error or produces incorrect results. Therefore, use a command line like the following:
The Fortran math library defines a set of trigonometric functions whose arguments or results are specified in degrees rather than radians. These functions are also implemented in libm. The names of these functions are the same as the names of the standard versions but with the letter d appended: sind, cosd, and so on. (For float versions of degree-valued trigonometric functions, the f follows the d.) To use these functions, compile them in any mode except strict ANSI mode (-Aa). Use either extended ANSI mode (-Ae, the default), non-ANSI mode (-Ac), or -Aa -D_HPUX_SOURCE. The fpclassify macro is the HP version of the class function recommended by the IEEE standard. The ANSI/ISO C committee has also approved this macro for inclusion in the C9X standard. The fpclassify macro accepts either a double or a float argument. It returns an integer value that describes the class of the argument—that is, what kind of floating-point value it is. Table 4-1 “fpclassify Values” shows the values and their meanings, which are defined in math.h. Table 4-1 fpclassify Values
The list of classes is exhaustive: all IEEE floating-point values fall into one of these classes. The fpclassify macro never causes an exception, regardless of the operand. It is useful, therefore, for classifying an operand without risking an exception trap. Use the signbit macro to determine whether a value is negative or positive. To use the fpclassify macro, compile your program in any mode except strict ANSI mode (-Aa). Use either extended ANSI mode (-Ae, the default), non-ANSI mode (-Ac), or -Aa -D_HPUX_SOURCE. The following C function shows how you might use fpclassify and signbit to display the class and value of a double-precision number: Example 4-3 Sample Function: print_class.c
Other macros that test the class of a floating-point value are
See the online man pages for information about these macros. The C math library provides several functions that are not specified by the ANSI C standard but that are required by the COSE Common API Specification (Spec 1170) and the XPG4.2 specification. These functions are
To use these functions, compile your program in any mode except strict ANSI mode (-Aa). Use either extended ANSI mode (-Ae, the default), non-ANSI mode (-Ac), or -Aa -D_HPUX_SOURCE. The fenv(5) suite is a collection of functions in the C math library that allow an application to manipulate various modifiable control modes and status flags in the floating-point status register. Most of the functions in the fenv(5) suite have been approved by the ISO/ANSI C committee for inclusion in the C9X draft standard. For details on how to use these functions, see Chapter 5 “Manipulating the Floating-Point Status Register” and the online man pages. The tables in Appendix A “The C Math Library” also list all of the functions. The Basic Linear Algebra Subroutine (BLAS) library routines perform low-level vector and matrix operations. They have been tuned for maximum performance. The BLAS library is provided with the HP Fortran 90 and HP FORTRAN/9000 products only, but the routines in this library are callable from other languages than Fortran. To call BLAS library routines, use the -l compile-line option to link in the libblas library. For example, the following command line links a Fortran program with the BLAS library:
To link with the library from C, you must also specify the library path name on the command line. For more information about the BLAS library routines, see “Matrix Operations” and the HP Fortran 90 Programmer's Reference or the HP FORTRAN/9000 Programmer's Reference. In addition, online man pages for these routines are available.
The vector library (provided with the HP FORTRAN/9000 product only) performs vector and matrix operations.
For more information about the libvec routines, see the HP FORTRAN/9000 Programmer's Reference. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||