Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ log(3M) — HP-UX ANSI C A.09.00

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

isinf(3M)

isnan(3M)

matherr(3M)

exp(3M)

NAME

exp, log, log10, log2, pow, sqrt, cbrt − exponential, logarithm, power, square root, cube root functions

SYNOPSIS

#include <math.h>

double exp(double x);

double log(double x);

double log10(double x);

double log2(double x);

double pow(double x, double y);

double sqrt(double x);

double cbrt(double x);

float expf(float x);

float logf(float x);

float log10f(float x);

float log2f(float x);

float powf(float x, float y);

float sqrtf(float x);

float cbrtf(float x);

DESCRIPTION

exp() returns ex. 

log() returns the natural logarithm of x. The value of x must be positive. 

log10() returns the logarithm base ten of x. The value of x must be positive. 

log2() returns the logarithm base two of x. The value of x must be positive. 

pow() returns xy.  If x is 0.0, y must be positive.  If x is negative, y must be an integer. 

sqrt() returns the non-negative square root of x. The value of x must not be negative. 

cbrt() returns the cube root of x. The value of x must not be negative. 

expf(), logf(), log10f(), log2f(), powf(), sqrtf(), and cbrtf() are float versions of exp(), log(), log10(), log2(), pow(), sqrt(), and cbrt(); they take float arguments and return float results.  Their performance is significantly faster than that of the double versions of the functions.  Programs must be compiled in ANSI mode (with the -Aa option) in order to use these functions; otherwise, the compiler promotes the float arguments to double, and the functions return incorrect results. 

DEPENDENCIES

Series 300/400

log2(), cbrt(), expf(), logf(), log10f(), log2f(), powf(), sqrtf(), and cbrtf() are not supported on Series 300/400 systems. 

Series 700/800

log2(), cbrt(), expf(), logf(), log10f(), log2f(), powf(), sqrtf(), and cbrtf() are not specified by any standard (however, the float functions are named in accordance with the conventions specified in the "Future Library Directions" section of the ANSI C standard).  These functions are provided in the PA1.1 versions of the math library only.  The +DA1.1 option (default on Series 700 systems) links in a PA1.1 version automatically.  A PA1.1 library can also be linked in explicitly.  For more information, see the HP-UX Floating-Point Guide.

/lib/libm.a

exp() returns:

• +INFINITY when x is +INFINITY,

• 0.0 when x is −INFINITY. 

log(), log2(), and log10() return +INFINITY when x is +INFINITY. 

pow() returns +INFINITY when:

• Absolute value of x is greater than 1.0 and y is +INFINITY,

• Absolute value of x is less than 1.0 and y is −INFINITY,

• x is +INFINITY and y is greater than 0.0, or

• x is −INFINITY and y is an even integer. 

pow() returns −INFINITY when x is −INFINITY and y is an odd integer. 

pow() returns 0.0 when:

• Absolute value of x is greater than 1.0 and y is −INFINITY,

• Absolute value of x is less than 1.0 and y is +INFINITY,

• x is +INFINITY and y is less than 0.0. 

sqrt() and cbrt() return +INFINITY when x is +INFINITY. 

/lib/libM.a

exp() returns:

• +INFINITY when x is +INFINITY,

• 0.0 when x is −INFINITY. 

log(), log2(), and log10() return +INFINITY when x is +INFINITY. 

pow() returns 1.0 when x and y are both 0.0. 

pow() returns +INFINITY when:

• Absolute value of x is greater than 1.0 and y is +INFINITY,

• Absolute value of x is less than 1.0 and y is −INFINITY,

• x is +INFINITY and y is greater than 0.0, or

• x is −INFINITY and y is an even integer. 

pow() returns −INFINITY when x is −INFINITY and y is an odd integer. 

pow() returns 0.0 when:

• Absolute value of x is greater than 1.0 and y is −INFINITY,

• Absolute value of x is less than 1.0 and y is +INFINITY,

• x is +INFINITY and y is less than 0.0. 

sqrt() and cbrt() return +INFINITY when x is +INFINITY. 

ERRORS

/lib/libm.a

exp() returns HUGE_VAL when the correct value would overflow, or 0.0 when the correct value would underflow, and sets errno to ERANGE.  NaN is returned and errno is set to EDOM when x is NaN. 

log(), log2(), and log10() return −HUGE_VAL and set errno to EDOM when x is non-positive.  NaN is returned and errno is set to EDOM when x is NaN or −INFINITY.  A message indicating DOMAIN error (or SING error when x is 0.0) is printed on the standard error output in these cases. 

pow() returns 0.0 and sets errno to EDOM when x is 0.0 and y is negative, or when x is negative and y is not an integer.  NaN is returned and errno is set to EDOM when x or y is NaN.  In these cases a message indicating DOMAIN error is printed on the standard error output.  When the correct value for pow() would overflow or underflow, pow() returns ±HUGE_VAL or 0.0 respectively, and sets errno to ERANGE. 

sqrt() returns NaN and sets errno to EDOM when x is negative, NaN or −INFINITY.  A message indicating DOMAIN error is printed on the standard error output. 

cbrt() returns 0.0 and sets errno to EDOM when x is negative.  NaN is returned and errno is set to EDOM when x is NaN.  In these cases a message indicating DOMAIN error is printed on the standard error output.  When the correct value for cbrt() would overflow or underflow, cbrt() returns ±HUGE_VAL or 0.0 respectively, and sets errno to ERANGE. 

These error-handling procedures can be changed with the matherr() function (see matherr(3M)).

/lib/libM.a

No error messages are printed on the standard error output. 

exp() returns HUGE_VAL when the correct value would overflow, or 0.0 when the correct value would underflow, and sets errno to ERANGE.  NaN is returned and errno is set to EDOM when x is NaN. 

log(), log2(), and log10() return NaN and set errno to EDOM when x is negative, −INFINITY, or NaN.  −HUGE_VAL is returned and errno is set to EDOM when x is 0.0. 

pow() returns −HUGE_VAL and sets errno to EDOM when x is 0.0 and y is negative.  NaN is returned and errno is set to EDOM when x is negative and y is not an integer or when x or y is NaN.  When the correct value for pow() would overflow or underflow, pow() returns ±HUGE_VAL or 0.0 respectively, and sets errno to ERANGE. 

sqrt() returns NaN and sets errno to EDOM when x is negative, NaN or −INFINITY. 

cbrt() returns NaN and sets errno to EDOM when x is negative or when x is NaN.  When the correct value for cbrt() would overflow or underflow, cbrt() returns ±HUGE_VAL or 0.0 respectively, and sets errno to ERANGE. 

These error-handling procedures can be changed by using the _matherr() function (see matherr(3M)). Note that _matherr() is provided in order to assist in migrating programs from libm.a to libM.a and is not a part of XPG3, ANSI C, or POSIX. 

SEE ALSO

isinf(3M), isnan(3M), matherr(3M). 

STANDARDS CONFORMANCE

exp() in libm.a: AES, SVID2, XPG2, XPG3, FIPS 151-2, POSIX.1
exp() in libM.a: AES, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

log() in libm.a: AES, SVID2, XPG2, XPG3, FIPS 151-2, POSIX.1
log() in libM.a: AES, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

log10() in libm.a: AES, SVID2, XPG2, XPG3, FIPS 151-2, POSIX.1
log10() in libM.a: AES, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

pow() in libm.a: AES, SVID2, XPG2, XPG3, FIPS 151-2, POSIX.1
pow() in libM.a: AES, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

sqrt() in libm.a: AES, SVID2, XPG2, XPG3, FIPS 151-2, POSIX.1
sqrt() in libM.a: AES, XPG3, XPG4, FIPS 151-2, POSIX.1, ANSI C

Hewlett-Packard Company  —  HP-UX Release 9.0: August 1992

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026