12 #include "cln/float.h"
13 #include "cl_F_tran.h"
19 const cl_R atan (const cl_R& x, const cl_R& y)
22 // y=0 -> bei x>0: 0 als Ergebnis,
23 // bei x<0: pi als Ergebnis.
25 // x=0 -> bei y>0: pi/2 als Ergebnis.
26 // bei y<0: -pi/2 als Ergebnis.
28 // Falls x und y beide rational: beide in Floats umwandeln.
29 // 0 <= |y| <= x -> atan(y/x)
30 // 0 <= |x| <= y -> pi/2 - atan(x/y)
31 // 0 <= |x| <= -y -> -pi/2 - atan(x/y)
32 // 0 <= |y| <= -x -> für y>=0: pi + atan(y/x), für y<0: -pi + atan(y/x)
36 if (zerop(x)) // x=0 -> Error
37 { throw division_by_0_exception(); }
38 if (minusp(x)) // x<0 -> pi in Default-Float-Genauigkeit
44 if (zerop(y)) // y=0 -> Error
45 { throw division_by_0_exception(); }
46 if (minusp(y)) // y<0 -> -pi/2
47 { return - scale_float(pi(),-1); }
48 return scale_float(pi(),-1); // y>0 -> pi/2
52 // Check special case of rational numbers:
55 // x,y in Floats umwandeln:
56 x = cl_float(The(cl_RA)(x));
57 y = cl_float(The(cl_RA)(y));
59 // x,y nicht exakt =0, x/y und y/x werden Floats sein.
60 if (abs(x) >= abs(y)) {
62 var cl_F z = atanx(The(cl_F)(y/x));
63 // Division war erfolgreich, also x/=0.
65 // x<0 -> pi bzw. -pi addieren:
67 // y>=0 -> atan(y/x) + pi
70 // y<0 -> atan(y/x) - pi
76 var cl_F z = atanx(The(cl_F)(x/y));
77 // von pi/2 bzw. -pi/2 subtrahieren:
79 // y>=0 -> pi/2 - atan(x/y)
80 return scale_float(pi(z),-1) - z;
82 // y<0 -> -pi/2 - atan(x/y)
83 return - scale_float(pi(z),-1) - z;