BSD 3 development
[unix-history] / usr / lib / lib.b
CommitLineData
d4c95abe
BJ
1scale = 20
2define e(x){
3 auto a, b, c, d, e, g, w, y
4
5 t = scale
6 scale = t + .434*x + 1
7
8 w = 0
9 if(x<0){
10 x = -x
11 w = 1
12 }
13 y = 0
14 while(x>2){
15 x = x/2
16 y = y + 1
17 }
18
19 a=1
20 b=1
21 c=b
22 d=1
23 e=1
24 for(a=1;1==1;a++){
25 b=b*x
26 c=c*a+b
27 d=d*a
28 g = c/d
29 if(g == e){
30 g = g/1
31 while(y--){
32 g = g*g
33 }
34 scale = t
35 if(w==1) return(1/g)
36 return(g/1)
37 }
38 e=g
39 }
40}
41
42define l(x){
43 auto a, b, c, d, e, f, g, u, s, t
44 if(x <=0) return(1-10^scale)
45 t = scale
46
47 f=1
48 scale = scale + scale(x) - length(x) + 1
49 s=scale
50 while(x > 2){
51 s = s + (length(x)-scale(x))/2 + 1
52 if(s>0) scale = s
53 x = sqrt(x)
54 f=f*2
55 }
56 while(x < .5){
57 s = s + (length(x)-scale(x))/2 + 1
58 if(s>0) scale = s
59 x = sqrt(x)
60 f=f*2
61 }
62
63 scale = t + length(f) - scale(f) + 1
64 u = (x-1)/(x+1)
65
66 scale = scale + 1.1*length(t) - 1.1*scale(t)
67 s = u*u
68 b = 2*f
69 c = b
70 d = 1
71 e = 1
72 for(a=3;1==1;a=a+2){
73 b=b*s
74 c=c*a+d*b
75 d=d*a
76 g=c/d
77 if(g==e){
78 scale = t
79 return(u*c/d)
80 }
81 e=g
82 }
83}
84
85define s(x){
86 auto a, b, c, s, t, y, p, n, i
87 t = scale
88 y = x/.7853
89 s = t + length(y) - scale(y)
90 if(s<t) s=t
91 scale = s
92 p = a(1)
93
94 scale = 0
95 if(x>=0) n = (x/(2*p)+1)/2
96 if(x<0) n = (x/(2*p)-1)/2
97 x = x - 4*n*p
98 if(n%2!=0) x = -x
99
100 scale = t + length(1.2*t) - scale(1.2*t)
101 y = -x*x
102 a = x
103 b = 1
104 s = x
105 for(i=3; 1==1; i=i+2){
106 a = a*y
107 b = b*i*(i-1)
108 c = a/b
109 if(c==0){scale=t; return(s/1)}
110 s = s+c
111 }
112}
113
114define c(x){
115 auto t
116 t = scale
117 scale = scale+1
118 x = s(x+2*a(1))
119 scale = t
120 return(x/1)
121}
122
123define a(x){
124 auto a, b, c, d, e, f, g, s, t
125 if(x==0) return(0)
126 if(x==1)
127 if(scale<52)
128return(.7853981633974483096156608458198757210492923498437764/1)
129 t = scale
130 f=1
131 while(x > .5){
132 scale = scale + 1
133 x= -(1-sqrt(1.+x*x))/x
134 f=f*2
135 }
136 while(x < -.5){
137 scale = scale + 1
138 x = -(1-sqrt(1.+x*x))/x
139 f=f*2
140 }
141 s = -x*x
142 b = f
143 c = f
144 d = 1
145 e = 1
146 for(a=3;1==1;a=a+2){
147 b=b*s
148 c=c*a+d*b
149 d=d*a
150 g=c/d
151 if(g==e){
152 scale = t
153 return(x*c/d)
154 }
155 e=g
156 }
157}
158
159define j(n,x){
160auto a,b,c,d,e,g,i,s,k,t
161
162 t = scale
163 k = 1.36*x + 1.16*t - n
164 k = length(k) - scale(k)
165 if(k>0) scale = scale + k
166
167s= -x*x/4
168if(n<0){
169 n= -n
170 x= -x
171 }
172a=1
173c=1
174for(i=1;i<=n;i++){
175 a=a*x
176 c = c*2*i
177 }
178b=a
179d=1
180e=1
181for(i=1;1;i++){
182 a=a*s
183 b=b*i*(n+i) + a
184 c=c*i*(n+i)
185 g=b/c
186 if(g==e){
187 scale = t
188 return(g/1)
189 }
190 e=g
191 }
192}