1*7c478bd9Sstevel@tonic-gate/* Copyright (c) 1984 AT&T */ 2*7c478bd9Sstevel@tonic-gate/* All Rights Reserved */ 3*7c478bd9Sstevel@tonic-gate 4*7c478bd9Sstevel@tonic-gate 5*7c478bd9Sstevel@tonic-gate/* 6*7c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 7*7c478bd9Sstevel@tonic-gate * Use is subject to license terms. 8*7c478bd9Sstevel@tonic-gate * 9*7c478bd9Sstevel@tonic-gate * CDDL HEADER START 10*7c478bd9Sstevel@tonic-gate * 11*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 12*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 13*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 14*7c478bd9Sstevel@tonic-gate * with the License. 15*7c478bd9Sstevel@tonic-gate * 16*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 17*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 18*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 19*7c478bd9Sstevel@tonic-gate * and limitations under the License. 20*7c478bd9Sstevel@tonic-gate * 21*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 22*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 23*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 24*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 25*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 26*7c478bd9Sstevel@tonic-gate * 27*7c478bd9Sstevel@tonic-gate * CDDL HEADER END 28*7c478bd9Sstevel@tonic-gate */ 29*7c478bd9Sstevel@tonic-gate 30*7c478bd9Sstevel@tonic-gate/* #ident "%Z%%M% %I% %E% SMI" */ 31*7c478bd9Sstevel@tonic-gate 32*7c478bd9Sstevel@tonic-gatescale = 20 33*7c478bd9Sstevel@tonic-gatedefine e(x){ 34*7c478bd9Sstevel@tonic-gate auto a, b, c, d, e, g, w, y, t, r 35*7c478bd9Sstevel@tonic-gate r = ibase 36*7c478bd9Sstevel@tonic-gate ibase = A 37*7c478bd9Sstevel@tonic-gate 38*7c478bd9Sstevel@tonic-gate t = scale 39*7c478bd9Sstevel@tonic-gate scale = t + .434*x + 1 40*7c478bd9Sstevel@tonic-gate 41*7c478bd9Sstevel@tonic-gate w = 0 42*7c478bd9Sstevel@tonic-gate if(x<0){ 43*7c478bd9Sstevel@tonic-gate x = -x 44*7c478bd9Sstevel@tonic-gate w = 1 45*7c478bd9Sstevel@tonic-gate } 46*7c478bd9Sstevel@tonic-gate y = 0 47*7c478bd9Sstevel@tonic-gate while(x>2){ 48*7c478bd9Sstevel@tonic-gate x = x/2 49*7c478bd9Sstevel@tonic-gate y = y + 1 50*7c478bd9Sstevel@tonic-gate } 51*7c478bd9Sstevel@tonic-gate 52*7c478bd9Sstevel@tonic-gate a=1 53*7c478bd9Sstevel@tonic-gate b=1 54*7c478bd9Sstevel@tonic-gate c=b 55*7c478bd9Sstevel@tonic-gate d=1 56*7c478bd9Sstevel@tonic-gate e=1 57*7c478bd9Sstevel@tonic-gate for(a=1;1==1;a++){ 58*7c478bd9Sstevel@tonic-gate b=b*x 59*7c478bd9Sstevel@tonic-gate c=c*a+b 60*7c478bd9Sstevel@tonic-gate d=d*a 61*7c478bd9Sstevel@tonic-gate g = c/d 62*7c478bd9Sstevel@tonic-gate if(g == e){ 63*7c478bd9Sstevel@tonic-gate g = g/1 64*7c478bd9Sstevel@tonic-gate while(y--){ 65*7c478bd9Sstevel@tonic-gate g = g*g 66*7c478bd9Sstevel@tonic-gate } 67*7c478bd9Sstevel@tonic-gate scale = t 68*7c478bd9Sstevel@tonic-gate if(w==1){ 69*7c478bd9Sstevel@tonic-gate ibase = r 70*7c478bd9Sstevel@tonic-gate return(1/g) 71*7c478bd9Sstevel@tonic-gate } 72*7c478bd9Sstevel@tonic-gate ibase = r 73*7c478bd9Sstevel@tonic-gate return(g/1) 74*7c478bd9Sstevel@tonic-gate } 75*7c478bd9Sstevel@tonic-gate e=g 76*7c478bd9Sstevel@tonic-gate } 77*7c478bd9Sstevel@tonic-gate} 78*7c478bd9Sstevel@tonic-gate 79*7c478bd9Sstevel@tonic-gatedefine l(x){ 80*7c478bd9Sstevel@tonic-gate auto a, b, c, d, e, f, g, u, s, t, r, z 81*7c478bd9Sstevel@tonic-gate r = ibase 82*7c478bd9Sstevel@tonic-gate ibase = A 83*7c478bd9Sstevel@tonic-gate if(x <=0){ 84*7c478bd9Sstevel@tonic-gate z = 1-10^scale 85*7c478bd9Sstevel@tonic-gate ibase = r 86*7c478bd9Sstevel@tonic-gate return(z) 87*7c478bd9Sstevel@tonic-gate } 88*7c478bd9Sstevel@tonic-gate t = scale 89*7c478bd9Sstevel@tonic-gate 90*7c478bd9Sstevel@tonic-gate f=1 91*7c478bd9Sstevel@tonic-gate scale = scale + scale(x) - length(x) + 1 92*7c478bd9Sstevel@tonic-gate s=scale 93*7c478bd9Sstevel@tonic-gate while(x > 2){ 94*7c478bd9Sstevel@tonic-gate s = s + (length(x)-scale(x))/2 + 1 95*7c478bd9Sstevel@tonic-gate if(s>0) scale = s 96*7c478bd9Sstevel@tonic-gate x = sqrt(x) 97*7c478bd9Sstevel@tonic-gate f=f*2 98*7c478bd9Sstevel@tonic-gate } 99*7c478bd9Sstevel@tonic-gate while(x < .5){ 100*7c478bd9Sstevel@tonic-gate s = s + (length(x)-scale(x))/2 + 1 101*7c478bd9Sstevel@tonic-gate if(s>0) scale = s 102*7c478bd9Sstevel@tonic-gate x = sqrt(x) 103*7c478bd9Sstevel@tonic-gate f=f*2 104*7c478bd9Sstevel@tonic-gate } 105*7c478bd9Sstevel@tonic-gate 106*7c478bd9Sstevel@tonic-gate scale = t + length(f) - scale(f) + 1 107*7c478bd9Sstevel@tonic-gate u = (x-1)/(x+1) 108*7c478bd9Sstevel@tonic-gate 109*7c478bd9Sstevel@tonic-gate scale = scale + 1.1*length(t) - 1.1*scale(t) 110*7c478bd9Sstevel@tonic-gate s = u*u 111*7c478bd9Sstevel@tonic-gate b = 2*f 112*7c478bd9Sstevel@tonic-gate c = b 113*7c478bd9Sstevel@tonic-gate d = 1 114*7c478bd9Sstevel@tonic-gate e = 1 115*7c478bd9Sstevel@tonic-gate for(a=3;1==1;a=a+2){ 116*7c478bd9Sstevel@tonic-gate b=b*s 117*7c478bd9Sstevel@tonic-gate c=c*a+d*b 118*7c478bd9Sstevel@tonic-gate d=d*a 119*7c478bd9Sstevel@tonic-gate g=c/d 120*7c478bd9Sstevel@tonic-gate if(g==e){ 121*7c478bd9Sstevel@tonic-gate scale = t 122*7c478bd9Sstevel@tonic-gate ibase = r 123*7c478bd9Sstevel@tonic-gate return(u*c/d) 124*7c478bd9Sstevel@tonic-gate } 125*7c478bd9Sstevel@tonic-gate e=g 126*7c478bd9Sstevel@tonic-gate } 127*7c478bd9Sstevel@tonic-gate} 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gatedefine s(x){ 130*7c478bd9Sstevel@tonic-gate auto a, b, c, s, t, y, p, n, i, r 131*7c478bd9Sstevel@tonic-gate r = ibase 132*7c478bd9Sstevel@tonic-gate ibase = A 133*7c478bd9Sstevel@tonic-gate t = scale 134*7c478bd9Sstevel@tonic-gate y = x/.7853 135*7c478bd9Sstevel@tonic-gate s = t + length(y) - scale(y) 136*7c478bd9Sstevel@tonic-gate if(s<t) s=t 137*7c478bd9Sstevel@tonic-gate scale = s 138*7c478bd9Sstevel@tonic-gate p = a(1) 139*7c478bd9Sstevel@tonic-gate 140*7c478bd9Sstevel@tonic-gate scale = 0 141*7c478bd9Sstevel@tonic-gate if(x>=0) n = (x/(2*p)+1)/2 142*7c478bd9Sstevel@tonic-gate if(x<0) n = (x/(2*p)-1)/2 143*7c478bd9Sstevel@tonic-gate x = x - 4*n*p 144*7c478bd9Sstevel@tonic-gate if(n%2!=0) x = -x 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate scale = t + length(1.2*t) - scale(1.2*t) 147*7c478bd9Sstevel@tonic-gate y = -x*x 148*7c478bd9Sstevel@tonic-gate a = x 149*7c478bd9Sstevel@tonic-gate b = 1 150*7c478bd9Sstevel@tonic-gate s = x 151*7c478bd9Sstevel@tonic-gate for(i=3; 1==1; i=i+2){ 152*7c478bd9Sstevel@tonic-gate a = a*y 153*7c478bd9Sstevel@tonic-gate b = b*i*(i-1) 154*7c478bd9Sstevel@tonic-gate c = a/b 155*7c478bd9Sstevel@tonic-gate if(c==0){scale=t; ibase = r; return(s/1)} 156*7c478bd9Sstevel@tonic-gate s = s+c 157*7c478bd9Sstevel@tonic-gate } 158*7c478bd9Sstevel@tonic-gate} 159*7c478bd9Sstevel@tonic-gate 160*7c478bd9Sstevel@tonic-gatedefine c(x){ 161*7c478bd9Sstevel@tonic-gate auto t, r 162*7c478bd9Sstevel@tonic-gate r = ibase 163*7c478bd9Sstevel@tonic-gate ibase = A 164*7c478bd9Sstevel@tonic-gate t = scale 165*7c478bd9Sstevel@tonic-gate scale = scale+1 166*7c478bd9Sstevel@tonic-gate x = s(x+2*a(1)) 167*7c478bd9Sstevel@tonic-gate scale = t 168*7c478bd9Sstevel@tonic-gate ibase = r 169*7c478bd9Sstevel@tonic-gate return(x/1) 170*7c478bd9Sstevel@tonic-gate} 171*7c478bd9Sstevel@tonic-gate 172*7c478bd9Sstevel@tonic-gatedefine a(x){ 173*7c478bd9Sstevel@tonic-gate auto a, b, c, d, e, f, g, s, t, r, z 174*7c478bd9Sstevel@tonic-gate if(x==0) {return(0/1)} 175*7c478bd9Sstevel@tonic-gate r = ibase 176*7c478bd9Sstevel@tonic-gate ibase = A 177*7c478bd9Sstevel@tonic-gate if(x==1){ 178*7c478bd9Sstevel@tonic-gate z =.7853981633974483096156608458198757210492923498437764/1 179*7c478bd9Sstevel@tonic-gate ibase = r 180*7c478bd9Sstevel@tonic-gate if(scale<52)return(z) 181*7c478bd9Sstevel@tonic-gate } 182*7c478bd9Sstevel@tonic-gate t = scale 183*7c478bd9Sstevel@tonic-gate f=1 184*7c478bd9Sstevel@tonic-gate while(x > .5){ 185*7c478bd9Sstevel@tonic-gate scale = scale + 1 186*7c478bd9Sstevel@tonic-gate x= -(1-sqrt(1.+x*x))/x 187*7c478bd9Sstevel@tonic-gate f=f*2 188*7c478bd9Sstevel@tonic-gate } 189*7c478bd9Sstevel@tonic-gate while(x < -.5){ 190*7c478bd9Sstevel@tonic-gate scale = scale + 1 191*7c478bd9Sstevel@tonic-gate x = -(1-sqrt(1.+x*x))/x 192*7c478bd9Sstevel@tonic-gate f=f*2 193*7c478bd9Sstevel@tonic-gate } 194*7c478bd9Sstevel@tonic-gate s = -x*x 195*7c478bd9Sstevel@tonic-gate b = f 196*7c478bd9Sstevel@tonic-gate c = f 197*7c478bd9Sstevel@tonic-gate d = 1 198*7c478bd9Sstevel@tonic-gate e = 1 199*7c478bd9Sstevel@tonic-gate for(a=3;1==1;a=a+2){ 200*7c478bd9Sstevel@tonic-gate b=b*s 201*7c478bd9Sstevel@tonic-gate c=c*a+d*b 202*7c478bd9Sstevel@tonic-gate d=d*a 203*7c478bd9Sstevel@tonic-gate g=c/d 204*7c478bd9Sstevel@tonic-gate if(g==e){ 205*7c478bd9Sstevel@tonic-gate scale = t 206*7c478bd9Sstevel@tonic-gate ibase = r 207*7c478bd9Sstevel@tonic-gate return(x*c/d) 208*7c478bd9Sstevel@tonic-gate } 209*7c478bd9Sstevel@tonic-gate e=g 210*7c478bd9Sstevel@tonic-gate } 211*7c478bd9Sstevel@tonic-gate} 212*7c478bd9Sstevel@tonic-gate 213*7c478bd9Sstevel@tonic-gatedefine j(n,x){ 214*7c478bd9Sstevel@tonic-gateauto a,b,c,d,e,g,i,s,k,t, r 215*7c478bd9Sstevel@tonic-gate r = ibase 216*7c478bd9Sstevel@tonic-gate ibase = A 217*7c478bd9Sstevel@tonic-gate 218*7c478bd9Sstevel@tonic-gate t = scale 219*7c478bd9Sstevel@tonic-gate k = 1.36*x + 1.16*t - n 220*7c478bd9Sstevel@tonic-gate k = length(k) - scale(k) 221*7c478bd9Sstevel@tonic-gate if(k>0) scale = scale + k 222*7c478bd9Sstevel@tonic-gate 223*7c478bd9Sstevel@tonic-gates= -x*x/4 224*7c478bd9Sstevel@tonic-gateif(n<0){ 225*7c478bd9Sstevel@tonic-gate n= -n 226*7c478bd9Sstevel@tonic-gate x= -x 227*7c478bd9Sstevel@tonic-gate } 228*7c478bd9Sstevel@tonic-gatea=1 229*7c478bd9Sstevel@tonic-gatec=1 230*7c478bd9Sstevel@tonic-gatefor(i=1;i<=n;i++){ 231*7c478bd9Sstevel@tonic-gate a=a*x 232*7c478bd9Sstevel@tonic-gate c = c*2*i 233*7c478bd9Sstevel@tonic-gate } 234*7c478bd9Sstevel@tonic-gateb=a 235*7c478bd9Sstevel@tonic-gated=1 236*7c478bd9Sstevel@tonic-gatee=1 237*7c478bd9Sstevel@tonic-gatefor(i=1;1;i++){ 238*7c478bd9Sstevel@tonic-gate a=a*s 239*7c478bd9Sstevel@tonic-gate b=b*i*(n+i) + a 240*7c478bd9Sstevel@tonic-gate c=c*i*(n+i) 241*7c478bd9Sstevel@tonic-gate g=b/c 242*7c478bd9Sstevel@tonic-gate if(g==e){ 243*7c478bd9Sstevel@tonic-gate scale = t 244*7c478bd9Sstevel@tonic-gate ibase = r 245*7c478bd9Sstevel@tonic-gate return(g/1) 246*7c478bd9Sstevel@tonic-gate } 247*7c478bd9Sstevel@tonic-gate e=g 248*7c478bd9Sstevel@tonic-gate } 249*7c478bd9Sstevel@tonic-gate} 250*7c478bd9Sstevel@tonic-gate 251