Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ trig(3) — OSF/1 X2.0-8 MIPS

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

hypot(3)

isnan(3)

math(3)

matherr(3)

sinh(3)

sqrt(3)

sin(3)  —  Subroutines

Digital

NAME

sin, cos, tan, asin, acos, atan, atan2, trig − Computes the trigonometric and inverse trigonometric functions. 

LIBRARY

Math Library (libm.a)

SYNOPSIS

#include <math.h> double sin (
double x); float fsin (
float x); double asin (
double x); float fasin (
float x); double cos (
double x); float fcos (
float x); double acos (
double x); float facos (
float x); double tan (
double x); float ftan (
float x); double atan (
double x); float fatan (
float ); double atan2 (
double y, x); float fatan2 (
float y,x);

PARAMETERS

xSpecifies some double or float value. 

ySpecifies some double or float value. 

DESCRIPTION

The sin() and fsin() functions compute the sine of x, measured in radians. 

The cos() and fcos() functions compute the cosine of x, measured in radians. 

The tan() and ftan() functions compute the tangent of x, measured in radians. 

The asin() and fasin() functions compute the principal value of the arc sine of x, in the range [−π/2, π/2] radians.  The value of x must be in the domain [−1,1]. 

The acos() and facos() functions compute the principal value of the arc cosine of x, in the range [0, π] radians. The value of x must be in the domain [−1,1]. 

The atan() and fatan() functions compute the principal value of the arc tangent of x, in the range [−π/2, π/2] radians. 

The atan2() and fatan2() functions compute the principal value of the arc tangent of y/x, in the range [−π, π] radians, using the signs of both arguments to determine the quadrant of the return value. 

NOTES

The sin(), cos(), and tan() functions lose accuracy when passed a large value for the x parameter. 

AES Support Level:
Full use for double variants only (sin(), asin(), cos(), acos(), tan(), atan(), and atan2()). 

The atan() function defines atan2(0,0)=0. The reasons for assigning a value to atan(0,0) are as follows:

       •Programs that test arguments to avoid computing atan(0,0) must be indifferent to its value. Programs that require atan(0,0) to be invalid are vulnerable to diverse reactions to that invalidity on diverse computer systems. 

       •The atan() function is used mostly to convert from rectangular (x,y) to polar (r,theta) coordinates that must satisfy the following equations:

x = r∗cos theta
y = r∗sin theta

The preceding equations are satisfied when (x=0,y=0) is mapped to (r=0,theta=0). In general, conversions to polar coordinates should be computed in the following way:

  r := hypot(x,y);   ... := sqrt(x∗x+y∗y)
theta := atan2(y,x)

       •The preceding formulas need not be altered to cope in a reasonable way with signed zeros and infinities on computers that conform to the IEEE Standard for Binary Floating-Point Arithmetic (ANSI/IEEE Std 754); the versions of the hypot() and atan() functions that are provided for such computers are designed to handle all cases. That is why atan2(±0,−0) = ±π, for example.  In general, the preceding formulas are equivalent to the following ones:

r := sqrt(x∗x+y∗y); if r=0 then x := copysign(1,x);
if x > 0 then theta := 2∗atan(y/(r+x))
     else theta := 2∗atan((r-x)/y);

The exception is that if r is infinite, then the atan() function will yield an appropriate multiple of π/4 that would otherwise have to be obtained by taking limits. 

Let P stand for the number stored in the computer in place of π=3.141159 26535 89793 23846 26433... . Let "trig" stand for one of sin, cos, or tan. Then the expression trig(x) in a program produces an approximation to trig(xπ/P), and the expression atrig(x) approximates P/π∗atrig(x).  The approximations are close. 

In the codes that run on computers that conform to ANSI/IEEE Std 754, P differs from π by a fraction of an ulp (unit in the last place); the difference is important only if the argument x is huge, and even then the difference is overshadowed by the uncertainty in x. In addition, every trigonometric identity that does not involve π explicitly is satisfied equally well regardless of whether P=π.  For example, sin(x)∗∗2+cos(x)∗∗2=1 and sin(2x)=2sin(x)cos(x) to within a few ulp no matter how large x might be. Therefore, the difference between P and π is unlikely to affect scientific and engineering computations. 

RETURN VALUES

The sin() and cos() functions return the sine and cosine, respectively, of their parameters.  If x is NaN, NaN is returned. Otherwise, either errno is set to indicate an error, or NaN is returned. 

The tan() function returns the tangent of its parameter.  If x is NaN, NaN is returned. Otherwise, either errno is set to indicate an error, or NaN is returned. 

The asin() function returns the principal value of the arc sine of x.  Otherwise, the asin() function returns NaN and sets errno to [EDOM] if its parameters are not in the range −1 to +1. 

The acos() function returns the principal value of the arc cosine of x.  Otherwise, the acos() function returns NaN and sets errno to [EDOM] if its parameters are not in the range −1 to +1. 

The atan() function returns the principal value of the arc tangent of x.  If x is NaN, NaN is returned.  Otherwise, NaN is returned. 

The atan2() function returns the principal value of the arc tangent of y/x.  If x or y is NaN, NaN is returned. 

ERRORS

If the sin() or cos() function fails, errno may be set to one of the following values:

[EDOM]The value of x is NaN, or x is ±HUGE_VAL .

[ERANGE]The magnitude of x is such that total or partial loss of significance resulted. 

If the tan() function fails, errno may be set to one of the following values:

[ERANGE]The value to be returned would have caused overflow. 

[ERANGE]The value to be returned would have caused underflow, or the magnitude of x is such that total or partial loss of significance would result. 

[EDOM]The value x is NaN. 

If the asin() or acos() function fails, errno may be set to the following value:

[EDOM]The x parameter is not in the domain [-1,1]. 

If the atan() function fails, errno may be set to the following value:

[EDOM]The value of x is NaN. 

If the atan2() function fails, errno may be set to the following value:

[EDOM]Both arguments are zero or one of the arguments is NaN. 

ENVIRONMENT

In the SVID-2 habitat:

       •The float variants of trigonometric functions are not available. 

       •The sin(), cos(), and tan() functions lose accuracy when their argument is far from zero.  For an argument sufficiently large, these functions return zero when there would otherwise be a complete loss of significance. In this case, a message that indicates TLOSS error is printed on the standard error output. For a less extreme argument that causes only partial loss of significance, a PLOSS error is printed on the standard error output. 

       •Error-handling procedures can be changed using the matherr() function. 

RELATED INFORMATION

Functions: hypot(3), isnan(3), math(3), matherr(3), sinh(3), sqrt(3)
 

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