2 * $OpenBSD: bc.library,v 1.3 2007/02/03 21:15:06 otto Exp $
3 * $DragonFly: src/usr.bin/bc/bc.library,v 1.2 2007/09/01 18:42:08 pavalos Exp $
7 * Copyright (C) Caldera International Inc. 2001-2002.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code and documentation must retain the above
14 * copyright notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed or owned by Caldera
22 * 4. Neither the name of Caldera International, Inc. nor the names of other
23 * contributors may be used to endorse or promote products derived from
24 * this software without specific prior written permission.
26 * USE OF THE SOFTWARE PROVIDED FOR UNDER THIS LICENSE BY CALDERA
27 * INTERNATIONAL, INC. AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR
28 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
29 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
30 * IN NO EVENT SHALL CALDERA INTERNATIONAL, INC. BE LIABLE FOR ANY DIRECT,
31 * INDIRECT INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
35 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
36 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
41 * @(#)bc.library 5.1 (Berkeley) 4/17/91
46 auto a, b, c, d, e, g, t, w, y, r
52 if (x > 0) scale = (0.435*x)/1
53 scale = scale + t + length(scale + t) + 1
71 for (a = 1; 1 == 1; a++) {
83 if (w == 1) return (1/g)
91 auto a, b, c, d, e, f, g, u, s, t, r
105 s = length(x)-scale(x)
108 a = (2.31*s)/1 /* estimated integer part of the answer */
109 s = t + length(a) + 2 /* estimated length of the answer */
112 scale = (length(x) + scale(x))/2 + 1
113 if (scale < s) scale = s
119 scale = scale(x)/2 + 1
120 if (scale < s) scale = s
126 scale = t + length(f) + length((1.05*(t+length(f))/1)) + 1
134 for (a = 3; 1 == 1 ; a = a + 2) {
149 auto a, b, c, s, t, y, p, n, i, r
154 s = t + length(y) - scale(y)
160 if (x >= 0) n = (x/(2*p) + 1)/2
161 if (x < 0) n = (x/(2*p) - 1)/2
163 if (n % 2 != 0) x = -x
165 scale = t + length(1.2*t) - scale(1.2*t)
170 for (i =3 ; 1 == 1; i = i + 2) {
196 auto a, b, c, d, e, f, g, s, t, r
197 if (x == 0) return(0)
203 a = .7853981633974483096156608458198757210492923498437764/1
212 x = -(1 - sqrt(1. + x*x))/x
217 x = -(1 - sqrt(1. + x*x))/x
225 for (a = 3; 1 == 1; a = a + 2) {
240 auto a, b, c, d, e, g, i, s, k, t, r
245 k = 1.36*x + 1.16*t - n
246 k = length(k) - scale(k)
247 if (k > 0) scale = scale + k
256 for (i = 1; i <= n; i++) {
263 for (i = 1; 1; i++) {