bc.library - sbase - suckless unix tools
(HTM) git clone git://git.suckless.org/sbase
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) README
(DIR) LICENSE
---
bc.library (4261B)
---
1 /*
2 * Copyright (C) Caldera International Inc. 2001-2002.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code and documentation must retain the above
9 * copyright notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed or owned by Caldera
16 * International, Inc.
17 * 4. Neither the name of Caldera International, Inc. nor the names of other
18 * contributors may be used to endorse or promote products derived from
19 * this software without specific prior written permission.
20 *
21 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
22 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 * IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
26 * INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
27 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
30 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
31 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 */
34
35 /*
36 *
37 * @(#)bc.library 8.1 (Berkeley) 6/6/93
38 */
39
40 scale = 20
41 define e(x){
42 auto a, b, c, d, e, g, t, w, y
43
44 t = scale
45 scale = t + .434*x + 1
46
47 w = 0
48 if(x<0){
49 x = -x
50 w = 1
51 }
52 y = 0
53 while(x>2){
54 x = x/2
55 y = y + 1
56 }
57
58 a=1
59 b=1
60 c=b
61 d=1
62 e=1
63 for(a=1;1==1;a++){
64 b=b*x
65 c=c*a+b
66 d=d*a
67 g = c/d
68 if(g == e){
69 g = g/1
70 while(y--){
71 g = g*g
72 }
73 scale = t
74 if(w==1) return(1/g)
75 return(g/1)
76 }
77 e=g
78 }
79 }
80
81 define l(x){
82 auto a, b, c, d, e, f, g, u, s, t
83 if(x <=0) return(1-10^scale)
84 t = scale
85
86 f=1
87 scale = scale + scale(x) - length(x) + 1
88 s=scale
89 while(x > 2){
90 s = s + (length(x)-scale(x))/2 + 1
91 if(s>0) scale = s
92 x = sqrt(x)
93 f=f*2
94 }
95 while(x < .5){
96 s = s + (length(x)-scale(x))/2 + 1
97 if(s>0) scale = s
98 x = sqrt(x)
99 f=f*2
100 }
101
102 scale = t + length(f) - scale(f) + 1
103 u = (x-1)/(x+1)
104
105 scale = scale + 1.1*length(t) - 1.1*scale(t)
106 s = u*u
107 b = 2*f
108 c = b
109 d = 1
110 e = 1
111 for(a=3;1==1;a=a+2){
112 b=b*s
113 c=c*a+d*b
114 d=d*a
115 g=c/d
116 if(g==e){
117 scale = t
118 return(u*c/d)
119 }
120 e=g
121 }
122 }
123
124 define s(x){
125 auto a, b, c, s, t, y, p, n, i
126 t = scale
127 y = x/.7853
128 s = t + length(y) - scale(y)
129 if(s<t) s=t
130 scale = s
131 p = a(1)
132
133 scale = 0
134 if(x>=0) n = (x/(2*p)+1)/2
135 if(x<0) n = (x/(2*p)-1)/2
136 x = x - 4*n*p
137 if(n%2!=0) x = -x
138
139 scale = t + length(1.2*t) - scale(1.2*t)
140 y = -x*x
141 a = x
142 b = 1
143 s = x
144 for(i=3; 1==1; i=i+2){
145 a = a*y
146 b = b*i*(i-1)
147 c = a/b
148 if(c==0){scale=t; return(s/1)}
149 s = s+c
150 }
151 }
152
153 define c(x){
154 auto t
155 t = scale
156 scale = scale+1
157 x = s(x+2*a(1))
158 scale = t
159 return(x/1)
160 }
161
162 define a(x){
163 auto a, b, c, d, e, f, g, s, t
164 if(x==0) return(0)
165 if(x==1) {
166 if(scale<52) {
167 return(.7853981633974483096156608458198757210492923498437764/1)
168 }
169 }
170 t = scale
171 f=1
172 while(x > .5){
173 scale = scale + 1
174 x= -(1-sqrt(1.+x*x))/x
175 f=f*2
176 }
177 while(x < -.5){
178 scale = scale + 1
179 x = -(1-sqrt(1.+x*x))/x
180 f=f*2
181 }
182 s = -x*x
183 b = f
184 c = f
185 d = 1
186 e = 1
187 for(a=3;1==1;a=a+2){
188 b=b*s
189 c=c*a+d*b
190 d=d*a
191 g=c/d
192 if(g==e){
193 scale = t
194 return(x*c/d)
195 }
196 e=g
197 }
198 }
199
200 define j(n,x){
201 auto a,b,c,d,e,g,i,s,k,t
202
203 t = scale
204 k = 1.36*x + 1.16*t - n
205 k = length(k) - scale(k)
206 if(k>0) scale = scale + k
207
208 s= -x*x/4
209 if(n<0){
210 n= -n
211 x= -x
212 }
213 a=1
214 c=1
215 for(i=1;i<=n;i++){
216 a=a*x
217 c = c*2*i
218 }
219 b=a
220 d=1
221 e=1
222 for(i=1;1;i++){
223 a=a*s
224 b=b*i*(n+i) + a
225 c=c*i*(n+i)
226 g=b/c
227 if(g==e){
228 scale = t
229 return(g/1)
230 }
231 e=g
232 }
233 }