13 #include "cl_F_tran.h"
17 const cl_R atan (const cl_R& x, const cl_R& y)
20 // y=0 -> bei x>0: 0 als Ergebnis,
21 // bei x<0: pi als Ergebnis.
23 // x=0 -> bei y>0: pi/2 als Ergebnis.
24 // bei y<0: -pi/2 als Ergebnis.
26 // Falls x und y beide rational: beide in Floats umwandeln.
27 // 0 <= |y| <= x -> atan(y/x)
28 // 0 <= |x| <= y -> pi/2 - atan(x/y)
29 // 0 <= |x| <= -y -> -pi/2 - atan(x/y)
30 // 0 <= |y| <= -x -> für y>=0: pi + atan(y/x), für y<0: -pi + atan(y/x)
34 if (zerop(x)) // x=0 -> Error
35 { cl_error_division_by_0(); }
36 if (minusp(x)) // x<0 -> pi in Default-Float-Genauigkeit
42 if (zerop(y)) // y=0 -> Error
43 { cl_error_division_by_0(); }
44 if (minusp(y)) // y<0 -> -pi/2
45 { return - scale_float(cl_pi(),-1); }
46 return scale_float(cl_pi(),-1); // y>0 -> pi/2
50 // Check special case of rational numbers:
53 // x,y in Floats umwandeln:
54 x = cl_float(The(cl_RA)(x));
55 y = cl_float(The(cl_RA)(y));
57 // x,y nicht exakt =0, x/y und y/x werden Floats sein.
58 if (abs(x) >= abs(y)) {
60 var cl_F z = atanx(The(cl_F)(y/x));
61 // Division war erfolgreich, also x/=0.
63 // x<0 -> pi bzw. -pi addieren:
65 // y>=0 -> atan(y/x) + pi
68 // y<0 -> atan(y/x) - pi
74 var cl_F z = atanx(The(cl_F)(x/y));
75 // von pi/2 bzw. -pi/2 subtrahieren:
77 // y>=0 -> pi/2 - atan(x/y)
78 return scale_float(cl_pi(z),-1) - z;
80 // y<0 -> -pi/2 - atan(x/y)
81 return - scale_float(cl_pi(z),-1) - z;