]> www.ginac.de Git - cln.git/blob - src/float/transcendental/cl_F_sinh.cc
25ae007784eedc4eee842757f6aa355b266f6567
[cln.git] / src / float / transcendental / cl_F_sinh.cc
1 // sinh().
2
3 // General includes.
4 #include "cl_sysdep.h"
5
6 // Specification.
7 #include "cl_float.h"
8
9
10 // Implementation.
11
12 #include "cl_F_tran.h"
13 #include "cl_F.h"
14 #include "cl_lfloat.h"
15 #include "cl_LF.h"
16
17 const cl_F sinh (const cl_F& x)
18 {
19 // Methode:
20 // Genauigkeit erhöhen,
21 // e := Exponent aus (decode-float x)
22 // falls e<0: (sinh(x)/x)^2 errechnen, Wurzel ziehen, mit x multiplizieren.
23 // falls e>=0: y:=exp(x) errechnen, (scale-float (- y (/ y)) -1) bilden.
24
25         if (float_exponent(x) < 0) { // Exponent e abtesten
26                 // e<0
27                 // Rechengenauigkeit erhöhen
28                 if (longfloatp(x)) {
29                         DeclareType(cl_LF,x);
30                         #if 0
31                         if (TheLfloat(x)->len >= infty) {
32                                 var cl_LF xx = extend(x,TheLfloat(x)->len+1);
33                                 var cl_LF_cosh_sinh_t hyp = cl_coshsinh_ratseries(xx);
34                                 return cl_float(hyp.sinh,x);
35                         } else
36                         #endif
37                         if ((TheLfloat(x)->len >= 500)
38                             && (float_exponent(x) > (-(sintL)float_digits(x))>>1)) {
39                                 // verwende exp(x), schneller als cl_coshsinh_ratseries
40                                 // (aber nur bei 0 > e > -d/2, denn wir müssen, um
41                                 // Auslöschung zu verhindern, |e| Bits dazunehmen)
42                                 var cl_LF xx = extend(x,TheLfloat(x)->len+ceiling((uintL)(-float_exponent(x)),intDsize));
43                                 var cl_F y = exp(xx);
44                                 var cl_F z = scale_float(y - recip(y), -1); // (/ (- y (/ y)) 2)
45                                 return cl_float(z,x);
46                         } else {
47                                 var cl_LF xx = The(cl_LF)(cl_F_extendsqrt(x));
48                                 // Wurzel aus sinh(x)^2 bilden
49                                 var cl_LF z = sqrt(sinhx_naive(xx));
50                                 if (minusp(xx))
51                                         z = -z;
52                                 return cl_float(z,x);
53                         }
54                 } else {
55                         var cl_F xx = cl_F_extendsqrt(x);
56                         // Wurzel aus (sinh(x)/x)^2 mit x multiplizieren und wieder runden
57                         return cl_float(sqrt(sinhxbyx_naive(xx))*xx,x);
58                 }
59         } else {
60                 // e>=0 -> verwende exp(x)
61                 var cl_F y = exp(x);
62                 return scale_float(y - recip(y), -1); // (/ (- y (/ y)) 2)
63         }
64 }
65
66 // Timings of the two algorithms, on an i486 33 MHz, running Linux,
67 // applied to x = sqrt(2)-1 = 0.414...
68 //   N      naive  ratseries
69 //   10     0.008   0.037
70 //   25     0.034   0.115
71 //   50     0.13    0.33
72 //  100     0.50    1.07
73 //  250     3.3     5.2
74 //  500    14.2    18.8
75 // 1000    59      61
76 // 2500   297     247
77 // ==> ratseries faster for N >= 1300.