[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Base Operating System and Extensions Technical Reference, Volume 1

exp, expl, expm1, log, logl, log10, log10l, log1p, pow, or powl Subroutine

Purpose

Computes exponential, logarithm, and power functions.

Libraries

IEEE Math Library (libm.a)
or System V Math Library (libmsaa.a)

Syntax

#include <math.h>
double exp (x)
double x;
long double expl (x)
long double x;
double expm1 (x)
double x;
double log (x)
double x;
long double logl (x)
long double x;
double log10 (x)
double x;
long double log10l (x)
long double x;
double log1p (x)
double x;
double pow (x, y)
double x, y;
long double powl (x, y)
long double x, y;

Description

These subroutines are used to compute exponential, logarithm, and power functions.

The exp and expl subroutines returns exp (x).

The expm1 subroutine returns exp (x)-1.

The log and logl subroutines return the natural logarithm of the x parameter. The value of the x parameter must be positive.

The log10 and log10l subroutines return the logarithm base 10 of the x parameter . The value of x must be positive.

The log1p subroutine returns log (1 + x).

The pow and powl subroutines return x**y. If the x parameter is negative or 0, then the y parameter must be an integer. If the y parameter is 0, then the pow and powl subroutines return 1.0 for all the x parameters.

The expm1 and log1p subroutines are useful to guarantee that financial calculations of ( (1+x**n) -1) / x, are accurate when the x parameter is small (for example, when calculating small daily interest rates).

expm1(n * log1p(x))/x 

These subroutines also simplify writing accurate inverse hyperbolic functions.

Note: Compile any routine that uses subroutines from the libm.a library with the -lm flags. For example: to compile the pow.c file, enter:

cc pow.c -lm

Parameters

x Specifies some double-precision floating-point value.
y Specifies some double-precision floating-point value.

Error Codes

When using the libm.a library:

exp If the correct value would overflow, the exp subroutine returns a HUGE_VAL value and the errno global variable is set to a ERANGE value.
log If the x parameter is less than 0, the log subroutine returns a NaNQ value and sets errno to EDOM. If x= 0, the log subroutine returns a -HUGE_VAL value but does not modify errno.
log10 If the x parameter is less than 0, the log10 subroutine returns a NaNQ value and sets errno to EDOM. If x= 0, the log10 subroutine returns a -HUGE_VAL value but does not modify errno.
pow If the correct value overflows, the powsubroutine returns a HUGE_VAL value and sets errno to ERANGE. If the x parameter is negative and the y parameter is not an integer, the pow subroutine returns a NaNQ value and sets errno to EDOM. If x=0 and the y parameter is negative, the pow subroutine returns a HUGE_VAL value but does not modify errno.
powl If the correct value overflows, the powlsubroutine returns a HUGE_VAL value and sets errno to ERANGE. If the x parameter is negative and the y parameter is not an integer, the powl subroutine returns a NaNQ value and sets errno to EDOM. If x=0 and the y parameter is negative, the powl subroutine returns a HUGE_VAL value but does not modify errno.

When using libmsaa.a(-lmsaa):

exp If the correct value would overflow, the exp subroutine returns a HUGE_VAL value. If the correct value would underflow, the exp subroutine returns 0. In both cases errno is set to ERANGE.
expl If the correct value would overflow, the expl subroutine returns a HUGE_VAL value. If the correct value would underflow, the expl subroutine returns 0. In both cases errno is set to ERANGE.
log If the x parameter is not positive, the log subroutine returns a -HUGE_VAL value, and sets errno to a EDOM value. A message indicating DOMAIN error (or SING error when x = 0) is output to standard error.
logl If the x parameter is not positive, the logl subroutine returns the -HUGE_VAL value, and sets errno to EDOM. A message indicating DOMAIN error (or SING error when x = 0) is output to standard error.
log10 If the x parameter is not positive, the log10 subroutine returns a -HUGE_VAL value and sets errno to EDOM. A message indicating DOMAIN error (or SING error when x = 0) is output to standard error.
log10l If the x parameter is not positive, the log10l subroutine returns a -HUGE_VAL value and sets errno to EDOM. A message indicating DOMAIN error (or SING error when x = 0) is output to standard error.
pow If x=0 and the y parameter is not positive, or if the x parameter is negative and the y parameter is not an integer, the pow subroutine returns 0 and sets errno to EDOM. In these cases a message indicating DOMAIN error is output to standard error. When the correct value for the pow subroutine would overflow or underflow, the pow subroutine returns:
+HUGE_VAL
 
 OR
 
 -HUGE_VAL
 
 OR
 
 0

When using either the libm.a library or the libsaa.a library:

expl If the correct value overflows, the expl subroutine returns a HUGE_VAL value and errno is set to ERANGE.
logl If x<0, the logl subroutine returns a NaNQ value
log10l If x < 0, log10l returns the value NaNQ and sets errno to EDOM. If x equals 0, log10l returns the value -HUGE_VAL but does not modify errno.
powl If the correct value overflows, powl returns HUGE_VAL and errno to ERANGE. If x is negative and y is not an integer, powl returns NaNQ and sets errno to EDOM. If x = zero and y is negative, powl returns a HUGE_VAL value but does not modify errno.

These error-handling procedures may be changed with the matherr subroutine when using the libmsaa.a library.

Implementation Specifics

The exp, expl, expm1, log, logl, log10, log10l, log1p, pow, or powl subroutines are part of Base Operating System (BOS) Runtime.

The expm1 and log1p subroutines are not part of the ANSI C Library.

Related Information

The hypot or cabs subroutine, matherr subroutine, sinh, cosh, or tanh subroutine.

Subroutines Overview in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.

128-Bit long double Floating-Point Format in AIX Version 4.3 General Programming Concepts: Writing and Debugging Programs.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]