Document revision date: 30 March 2001

## Compaq Portable Mathematics Library

Previous | Contents | Index

## 1.5 IEEE Std 754 Considerations

The Institute of Electrical and Electronics Engineers (IEEE) ANSI/IEEE Std 754-1985, IEEE Standard for Binary Floating-Point Arithmetic data types include denormalized numbers (very close to zero). The standard supports the concept of "Not-a-Number" or NaN to represent indeterminate quantities, and uses plus infinity or minus infinity (so that they behave in arithmetic) like the mathematical infinities. Whenever a CPML routine produces an overflow or indeterminate condition, it generates an infinity or NaN value.

All CPML routines, except one, return a NaN result when presented with a NaN input. The only exception is pow(NaN,0) = 1 in ANSI C.

## 1.6 X/Open Portability Guide Considerations

Table 1-4 lists the routines described in this manual that conform to the requirements of the X/Open Portability Guide, Version 4 (XPG4), or are implemented as UNIX extensions to the XPG4 standard (XPG4-UNIX). Descriptions of these routines appear in Chapter 2 under the generic function name listed in Table 1-4. Platform-specific entry-points are listed in Appendix B.

Table 1-4 XPG4 Conformant Routines
Routine | Conforms to Standard | Generic Function Name
--- | --- | ---
acos | XPG4 | acos
acosh | XPG4-UNIX | acosh
asin | XPG4 | asin
asinh | XPG4-UNIX | asinh
atan | XPG4 | atan
atan2 | XPG4 | atan
atanh | XPG4-UNIX | atanh
ceil | XPG4 | ceil
cos | XPG4 | cos
cosh | XPG4 | cosh
cot | XPG4 | cot
erf | XPG4 | erf
erfc | XPG4 | erf
exp | XPG4 | exp
expm1 | XPG4-UNIX | exp
fabs | XPG4 | fabs
floor | XPG4 | floor
fmod | XPG4 | fmod
frexp | XPG4 | frexp
gamma | XPG4 | lgamma
hypot | XPG4 | hypot
ilogb | XPG4-UNIX | ilogb
isnan | XPG4 | isnan
j0 | XPG4 | bessel
j1 | XPG4 | bessel
jn | XPG4 | bessel
ldexp | XPG4 | ldexp
lgamma | XPG4 | lgamma
log | XPG4 | log
log10 | XPG4 | log
log1p | XPG4-UNIX | log
logb | XPG4-UNIX | logb
modf | XPG4 | modf
nextafter | XPG4-UNIX | nextafter
pow | XPG4 | pow
remainder | XPG4-UNIX | remainder
rint | XPG4-UNIX | rint
scalb | XPG4-UNIX | scalb
sin | XPG4 | sin
sinh | XPG4 | sinh
tan | XPG4 | tan
tanh | XPG4 | tanh
y0 | XPG4 | bessel
y1 | XPG4 | bessel
yn | XPG4 | bessel

## Chapter 2
CPML Routines

CPML routines can be accessed from high-level languages that support mathematical functions (such as Fortran and C), or called directly using standard call interfaces. It is highly recommended that you invoke CPML routines only from a high-level language.

CPML routines are documented with generic names, and with the symbol F_TYPE to indicate generic floating-point values (e.g. F_ TYPE sqrt (F_TYPE x)).

To determine the appropriate names and interfaces within a specific programming language (e.g. float sqrtf(float x) or REAL*4 SQRT), refer to that language's documentation.

To enable the use of CPML routines which are not provided by your high-level language, the actual CPML entrynames are provided.

Note: CPML routines which return complex numbers ("F_COMPLEX") use a private interface. Therefore, they can only be called from high-level languages that support that interface.

The Data Types S_FLOAT, T_FLOAT and X_FLOAT refer to IEEE format floating-point numbers of single-, double-, and quad-precision, respectively. F_FLOAT and G_FLOAT refer to VAX format single- precision, and G-floating double-precision floating point numbers, respectively.

For each CPML routine, "exceptional" input values are also provided. That is, values for which the function is mathematically undefined, or for which the output would be out of range for the floating-point type.

Refer to your language's documentation for information about how exceptions manifest themselves and how to control exception behavior.

Further information is also available at the Compaq Math website at: http://www.compaq.com/math.

## 2.1 CPML Routine Descriptions

CPML routines are described in detail at the end of this chapter. Each CPML routine documented in this chapter is presented in the following format:

- Routine name---A brief name to identify the function of the routine. A routine may contain more than one function.
- Interface---What the routine expects to receive and what it returns. See Section 2.2 for more information.
- Description---Additional information, including the permitted range of input values and generic calculations used to compute the results.
- Exceptions---A description of how the routine behaves when given a specific exceptional input argument.

## 2.2 CPML Routine Interface

The interface to each function is:

RETURN_TYPE generic_interface_name (INPUT_ARG_TYPE...)

Each of these is described below.

> #### RETURN_TYPE

> The data type of the value that the routine returns to your application program. Each routine returns a specific class of data type. For example, either F_TYPE or F_COMPLEX can appear in a CPML interface as described in Chapter 2. The supported data types are described in Section 1.2.

> #### generic_interface_name

> The generic name. CPML routines in this chapter are listed in alphabetic order by their interface names. Some CPML routines may be available in the syntax of your high-level language. Fortran and C are examples. To maximize the portability of your application, use the corresponding mathematical routine described in your high-level language, and directly call only the routines documented in this manual that are not supported by your language. Refer to Appendix B for the specific entry-point names needed to directly call a CPML routine from your platform.

> #### INPUT_ARG_TYPE...

> The number and type of input arguments provided by your application. Some routines require more than one argument. Arguments must be coded in the order shown in the interface section of each routine described in this chapter. The supported data types for arguments are described in Section 1.2.

> Note Unless otherwise noted, arguments are read-only and passed by value. Arguments passed by another mechanism are prefaced by an asterisk (*); for example, *n in the frexp() routine.

## 2.3 Specific Entry-Point Names

Each generic interface name documented in the interface section of a routine description corresponds to one or more specific entry-point names described in Appendix B. For example, on OpenVMS Alpha systems, the acosd function has five entry-point names, one for each available floating-point data type. The acosd entry-point names are math$acosd_f, math$acosd_s, math$acosd_x, math$acosd_g, and math$acosd_t. On Compaq Tru64 UNIX Alpha systems, the acosd function has two entry-point names corresponding to their supported data types: S_FLOAT and T_FLOAT. The two entry-point names are acosdf for S_FLOAT input arguments and acosd for T_FLOAT arguments. Use the specific entry-point name that corresponds to the input argument data type.

## 2.4 Working with Exception Conditions

Each CPML routine description contains a table of exceptions. Each exception listed in the table represents an exceptional case that is handled in a platform-specific manner. For example, the atan2() exception table contains the following two entries:

Exceptional Argument | Routine Behavior
--- | ---
y = x = 0 | Invalid argument
|y| = |x| = infinity | Invalid argument

The first entry describes an exception condition containing two input arguments with zero values. Upon detecting this error, the routine behavior signals the "invalid argument" condition. The second entry is applicable only to platforms supporting signed or unsigned infinity values. Here, if the absolute value of both input arguments is equal to infinity, an "invalid argument" condition is signaled.

The exact behavior of a routine that detects an exceptional argument varies from platform to platform and is sometimes dependent on the environment in which it is called. The behavior you see depends on the platform and language used. It also depends on how the routine was called and the interaction of the various layers of software through which the call to the routine was made. Remember, access to a CPML routine can be made either through direct access (a CALL statement written by a programmer in a source code statement) or through indirect access (from compiler-implemented mathematical syntax).

The default behavior for detecting the x=y=0 arguments is to generate an exception trap when accessing atan2() indirectly through Fortran compiler syntax. C compiler syntax for the atan2() routine sets errno and returns a NaN when give the same input. In these cases, your compiler documentation provides you with information on how to work with exception conditions.

## 2.5 CPML Routine Interface Examples

This section discusses the atan2() and cdiv() interfaces and explains how to interpret them. The explanations given in this section apply to all CPML routines.

### 2.5.1 atan2() Interface

The interface to the atan2() routine is:

F_TYPE atan2 (F_TYPE y, F_TYPE x)

The routine name atan2() is the high-level language source-level name that gets mapped to a specific entry-point name documented in Appendix B. This is the name that appears in compiler documentation for this mathematical routine. The appropriate entry-point name is automatically selected when atan2() is called from high-level language syntax. This selection depends upon the data type of the input arguments. If you make direct calls to this routine, you must manually select the proper entry-point name documented in Appendix B for the data type of your input arguments.

The format of the atan2() routine shows that it expects to receive two input arguments by value. Both arguments must be the same F_TYPE. The returned value will also be the same F_TYPE as the input arguments.

For example, on OpenVMS Alpha systems, the G_FLOAT entry-point name is math$atan2_g(). It takes two G_FLOAT arguments by value and returns a G_FLOAT result.

For Compaq Tru64 UNIX Alpha systems, the S_FLOAT entry-point name is atan2f(). The routine takes two S_FLOAT input arguments by value and returns an S_FLOAT result.

### 2.5.2 cdiv() Interface

The interface to the cdiv() routine is:

F_COMPLEX cdiv (F_TYPE a, F_TYPE b, F_TYPE c, F_TYPE d)

The routine name cdiv() is the generic name that gets mapped to a specific entry-point name documented in Appendix B. Selection of the appropriate entry-point name is done automatically when cdiv() is called from high-level language syntax. This selection depends upon the data type of the input arguments. Again, if you make direct calls to this routine, you must manually select the proper entry-point name documented in Appendix B for the data type of your input arguments.

The format of the cdiv() routine shows that it expects to receive four input arguments by value. All arguments must be the same F_TYPE. The returned value will be an F_COMPLEX data type and will be the same base data type as the input arguments.

For example, on OpenVMS Alpha systems, the F_FLOAT entry-point name is math$cdiv_f(). This routine takes four F_FLOAT input arguments by value and returns an F_FLOAT_COMPLEX result in an ordered pair of F_FLOAT quantities.

For Compaq Tru64 UNIX Alpha systems, the S_FLOAT entry-point name is cdivf(). This routine takes four S_FLOAT input arguments by value and returns an S_FLOAT_COMPLEX result.

## acos - Arc Cosine of Angle

### Interface

> F_TYPE acos (F_TYPE x)

> F_TYPE acosd (F_TYPE x)

### Description

> acos() computes the principal value of the arc cosine of x in the interval [0,pi] radians for x in the interval [-1,1].

> acosd() computes the principal value of the arc cosine of x in the interval [0,180] degrees for x in the interval [-1,1].

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
|x|>1 | Invalid argument

## acosh - Hyperbolic Arc Cosine of Angle

### Interface

> F_TYPE acosh (F_TYPE x)

### Description

> acosh() returns the hyperbolic arc cosine of x for x in the interval [1,+infinity]. acosh(x) = ln(x + sqrt(x**2 - 1)).

> acosh() is the inverse function of cosh(). The definition of the acosh() function is acosh(cosh (x)) = x.

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
x<1 | Invalid argument

## asin - Arc Sine of Angle

### Interface

> F_TYPE asin (F_TYPE x)

> F_TYPE asind (F_TYPE x)

### Description

> asin() computes the principal value of the arc sine of x in the interval [-pi/2,pi/2] radians for x in the interval [-1,1].

> asind() computes the principal value of the arc sine of x in the interval [-90,90] degrees for x in the interval [-1,1].

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
|x|>1 | Invalid argument

## asinh - Hyperbolic Arc Sine of Angle

### Interface

> F_TYPE asinh (F_TYPE x)

### Description

> asinh() returns the hyperbolic arc sine of x for x in the interval [-infinity, +infinity]. asinh(x) = ln(x + sqrt(x**2 + 1)).

> asinh() is the inverse function of sinh(). asinh(sinh (x)) = x.

#### Exceptions

None.

## atan - Arc Tangent of Angle with One Argument

### Interface

> F_TYPE atan (F_TYPE x)

> F_TYPE atand (F_TYPE x)

### Description

> atan() computes the principal value of the arc tangent of x in the interval [-pi/2,pi/2] radians for x in the interval [-infinity, +infinity].

> atand() computes the principal value of the arc tangent of x in the interval [-90,90] degrees for x in the interval [-infinity, +infinity].

#### Exceptions

None.

## atan2 - Arc Tangent of Angle with Two Arguments

### Interface

> F_TYPE atan2 (F_TYPE y, F_TYPE x)

> F_TYPE atand2 (F_TYPE y, F_TYPE x)

### Description

> atan2() computes the angle in the interval [-pi,pi] whose arc tangent is y/x radians for x and y in the interval [-infinity, +infinity]. The sign of atan2() is the same as the sign of y. The atan2(y, x) function is computed as follows, where f is the number of fraction bits associated with the data type:

> Value of Input Arguments | Angle Returned
> --- | ---
> x = 0 or y/x > 2 f+1 | Pi sign/2 * (sign y)
> x > 0 and y/x <= 2 f+1 | atan(y/x)
> x < 0 and y/x <= 2 f+1 | Pi sign * (sign y) + atan(y/x)

> atand2() computes the angle in the interval [-180,180] whose arc tangent is y/x degrees for x and y in the interval [-infinity, +infinity]. The sign of atand2() is the same as the sign of y.

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
y = x = 0 | Invalid argument
|y| = infinity and |x| = infinity | Invalid argument

## atanh - Hyperbolic Arc Tangent of Angle

### Interface

> F_TYPE atanh (F_TYPE x)

### Description

> atanh() returns the hyperbolic arc tangent of x for x in the interval (-1,1). atanh() is the inverse function of tanh(). atanh(tanh (x)) = x.

> atanh(x) is computed as 1/2 ln((1+x)/(1-x)).

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
|x| > or = 1 | Invalid argument

## bessel - Bessel Functions

### Interface

> F_TYPE j0 (F_TYPE x)

> F_TYPE j1 (F_TYPE x)

> F_TYPE jn (int n, F_TYPE x)

> F_TYPE y0 (F_TYPE x)

> F_TYPE y1 (F_TYPE x)

> F_TYPE yn (int n, F_TYPE x)

### Description

> j0() and j1() return the value of the Bessel function of the first kind of orders 0 and 1, respectively.

> jn() returns the value of the Bessel function of the first kind of order n.

> y0() and y1() return the value of the Bessel function of the second kind of orders 0 and 1, respectively.

> yn() returns the value of the Bessel function of the second kind of order n.

> The value of x must be positive for the y family of Bessel functions. The value of n specifies some integer value.

#### Exceptions

Exceptional Argument | Routine Behavior
--- | ---
(y0(), y1(), yn()) x < 0 | Invalid argument
(y0(), y1(), yn()) x = 0 | Overflow

The j1() and jn() functions can result in an underflow as x becomes small. The largest value of x for which this occurs is a function of n.
The y1() and yn() functions can result in an overflow as x becomes small. The largest value of x for which this occurs is a function of n.

Previous | Next | Contents | Index

| privacy and legal statement |
6118PRO_001.HTML