1 2 /* @(#)w_atan2.c 5.1 93/09/24 */ 3 /* 4 * ==================================================== 5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 * 7 * Developed at SunPro, a Sun Microsystems, Inc. business. 8 * Permission to use, copy, modify, and distribute this 9 * software is freely granted, provided that this notice 10 * is preserved. 11 * ==================================================== 12 * 13 */ 14 15 /* 16 FUNCTION 17 <<atan2>>, <<atan2f>>---arc tangent of y/x 18 19 INDEX 20 atan2 21 INDEX 22 atan2f 23 24 ANSI_SYNOPSIS 25 #include <math.h> 26 double atan2(double <[y]>,double <[x]>); 27 float atan2f(float <[y]>,float <[x]>); 28 29 TRAD_SYNOPSIS 30 #include <math.h> 31 double atan2(<[y]>,<[x]>); 32 double <[y]>; 33 double <[x]>; 34 35 float atan2f(<[y]>,<[x]>); 36 float <[y]>; 37 float <[x]>; 38 39 DESCRIPTION 40 41 <<atan2>> computes the inverse tangent (arc tangent) of <[y]>/<[x]>. 42 <<atan2>> produces the correct result even for angles near 43 @ifinfo 44 pi/2 or -pi/2 45 @end ifinfo 46 @tex 47 $\pi/2$ or $-\pi/2$ 48 @end tex 49 (that is, when <[x]> is near 0). 50 51 <<atan2f>> is identical to <<atan2>>, save that it takes and returns 52 <<float>>. 53 54 RETURNS 55 <<atan2>> and <<atan2f>> return a value in radians, in the range of 56 @ifinfo 57 -pi to pi. 58 @end ifinfo 59 @tex 60 $-\pi$ to $\pi$. 61 @end tex 62 63 If both <[x]> and <[y]> are 0.0, <<atan2>> causes a <<DOMAIN>> error. 64 65 You can modify error handling for these functions using <<matherr>>. 66 67 PORTABILITY 68 <<atan2>> is ANSI C. <<atan2f>> is an extension. 69 70 71 */ 72 73 /* 74 * wrapper atan2(y,x) 75 */ 76 77 #include "fdlibm.h" 78 #include <errno.h> 79 80 #ifndef _DOUBLE_IS_32BITS 81 82 #ifdef __STDC__ atan2(double y,double x)83 double atan2(double y, double x) /* wrapper atan2 */ 84 #else 85 double atan2(y,x) /* wrapper atan2 */ 86 double y,x; 87 #endif 88 { 89 #ifdef _IEEE_LIBM 90 return __ieee754_atan2(y,x); 91 #else 92 double z; 93 struct exception exc; 94 z = __ieee754_atan2(y,x); 95 if(_LIB_VERSION == _IEEE_||isnan(x)||isnan(y)) return z; 96 if(x==0.0&&y==0.0) { 97 /* atan2(+-0,+-0) */ 98 exc.arg1 = y; 99 exc.arg2 = x; 100 exc.type = DOMAIN; 101 exc.name = "atan2"; 102 exc.err = 0; 103 exc.retval = 0.0; 104 if(_LIB_VERSION == _POSIX_) 105 errno = EDOM; 106 else if (!matherr(&exc)) { 107 errno = EDOM; 108 } 109 if (exc.err != 0) 110 errno = exc.err; 111 return exc.retval; 112 } else 113 return z; 114 #endif 115 } 116 117 #endif /* defined(_DOUBLE_IS_32BITS) */ 118