| 1 | #include <math.h> | 
|---|
| 2 |  | 
|---|
| 3 | /* @(#) $Id: actan.c,v 1.7 2008-03-25 17:45:08 cmv Exp $ */ | 
|---|
| 4 |  | 
|---|
| 5 | /* commonly in math.h, but not in strict ANSI C */ | 
|---|
| 6 | #ifndef M_PI | 
|---|
| 7 | #define M_PI            3.14159265358979323846 | 
|---|
| 8 | #define M_PI_2          1.57079632679489661923 | 
|---|
| 9 | #endif | 
|---|
| 10 |  | 
|---|
| 11 | double | 
|---|
| 12 | actan(double sinx, double cosx) | 
|---|
| 13 | { | 
|---|
| 14 | double ret; | 
|---|
| 15 |  | 
|---|
| 16 | ret = 0.0; | 
|---|
| 17 | if(cosx < 0.0) { | 
|---|
| 18 | ret = M_PI; | 
|---|
| 19 | } else if(cosx == 0.0) { | 
|---|
| 20 | if(sinx < 0.0) { | 
|---|
| 21 | return 3.0 * M_PI_2; | 
|---|
| 22 | } else if(sinx == 0.0) { | 
|---|
| 23 | return ret; | 
|---|
| 24 | } else /* sinx > 0.0 */ { | 
|---|
| 25 | return M_PI_2; | 
|---|
| 26 | } | 
|---|
| 27 | } else /* cosx > 0.0 */ { | 
|---|
| 28 | if(sinx < 0.0) { | 
|---|
| 29 | ret = 2.0 * M_PI; | 
|---|
| 30 | } else if(sinx == 0.0) { | 
|---|
| 31 | return ret; | 
|---|
| 32 | } | 
|---|
| 33 | } | 
|---|
| 34 |  | 
|---|
| 35 | return ret + atan(sinx / cosx); | 
|---|
| 36 | } | 
|---|
| 37 |  | 
|---|
| 38 |  | 
|---|
| 39 | #if 0 | 
|---|
| 40 |  | 
|---|
| 41 | #define D(X) (180.0 * (X) / M_PI) | 
|---|
| 42 |  | 
|---|
| 43 | void main() { | 
|---|
| 44 | double a, b; | 
|---|
| 45 |  | 
|---|
| 46 | a =  0.0; b =  2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 47 | a =  1.0; b =  2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 48 | a =  2.0; b =  2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 49 | a =  2.0; b =  1.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 50 | a =  2.0; b =  0.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 51 | a =  2.0; b = -1.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 52 | a =  2.0; b = -2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 53 | a =  1.0; b = -2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 54 | a =  0.0; b = -2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 55 | a = -1.0; b = -2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 56 | a = -2.0; b = -2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 57 | a = -2.0; b = -1.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 58 | a = -2.0; b =  0.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 59 | a = -2.0; b =  1.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 60 | a = -2.0; b =  2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 61 | a = -1.0; b =  2.0; printf("actan(%f, %f) = %f\n", a, b, D(actan(a, b))); | 
|---|
| 62 | } | 
|---|
| 63 |  | 
|---|
| 64 | #endif /* 0 */ | 
|---|
| 65 |  | 
|---|
| 66 | /* For RCS Only -- Do Not Edit */ | 
|---|
| 67 | static char *rcsid[2] = {(char *)rcsid, "@(#) $RCSfile: actan.c,v $ $Date: 2008-03-25 17:45:08 $ $Revision: 1.7 $ $Name: not supported by cvs2svn $"}; | 
|---|