1 2 /* 3 * IBM Accurate Mathematical Library 4 * written by International Business Machines Corp. 5 * Copyright (C) 2001 Free Software Foundation 6 * 7 * This program is free software; you can redistribute it and/or modify 8 * it under the terms of the GNU Lesser General Public License as published by 9 * the Free Software Foundation; either version 2.1 of the License, or 10 * (at your option) any later version. 11 * 12 * This program is distributed in the hope that it will be useful, 13 * but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * GNU Lesser General Public License for more details. 16 * 17 * You should have received a copy of the GNU Lesser General Public License 18 * along with this program; if not, write to the Free Software 19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 */ 21 /******************************************************************/ 22 /* */ 23 /* MODULE_NAME:mpatan.c */ 24 /* */ 25 /* FUNCTIONS:mpatan */ 26 /* */ 27 /* FILES NEEDED: mpa.h endian.h mpatan.h */ 28 /* mpa.c */ 29 /* */ 30 /* Multi-Precision Atan function subroutine, for precision p >= 4.*/ 31 /* The relative error of the result is bounded by 34.32*r**(1-p), */ 32 /* where r=2**24. */ 33 /******************************************************************/ 34 35 #include "endian.h" 36 #include "mpa.h" 37 void __mpsqrt(mp_no *, mp_no *, int); 38 39 void __mpatan(mp_no *x, mp_no *y, int p) { 40 #include "mpatan.h" 41 42 int i,m,n; 43 double dx; 44 mp_no 45 mpone = {0,{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 46 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 47 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}}, 48 mptwo = {0,{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 49 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 50 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}}, 51 mptwoim1 = {0,{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 52 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0, 53 0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}}; 54 55 mp_no mps,mpsm,mpt,mpt1,mpt2,mpt3; 56 57 /* Choose m and initiate mpone, mptwo & mptwoim1 */ 58 if (EX>0) m=7; 59 else if (EX<0) m=0; 60 else { 61 __mp_dbl(x,&dx,p); dx=ABS(dx); 62 for (m=6; m>0; m--) 63 {if (dx>xm[m].d) break;} 64 } 65 mpone.e = mptwo.e = mptwoim1.e = 1; 66 mpone.d[0] = mpone.d[1] = mptwo.d[0] = mptwoim1.d[0] = ONE; 67 mptwo.d[1] = TWO; 68 69 /* Reduce x m times */ 70 __mul(x,x,&mpsm,p); 71 if (m==0) __cpy(x,&mps,p); 72 else { 73 for (i=0; i<m; i++) { 74 __add(&mpone,&mpsm,&mpt1,p); 75 __mpsqrt(&mpt1,&mpt2,p); 76 __add(&mpt2,&mpt2,&mpt1,p); 77 __add(&mptwo,&mpsm,&mpt2,p); 78 __add(&mpt1,&mpt2,&mpt3,p); 79 __dvd(&mpsm,&mpt3,&mpt1,p); 80 __cpy(&mpt1,&mpsm,p); 81 } 82 __mpsqrt(&mpsm,&mps,p); mps.d[0] = X[0]; 83 } 84 85 /* Evaluate a truncated power series for Atan(s) */ 86 n=np[p]; mptwoim1.d[1] = twonm1[p].d; 87 __dvd(&mpsm,&mptwoim1,&mpt,p); 88 for (i=n-1; i>1; i--) { 89 mptwoim1.d[1] -= TWO; 90 __dvd(&mpsm,&mptwoim1,&mpt1,p); 91 __mul(&mpsm,&mpt,&mpt2,p); 92 __sub(&mpt1,&mpt2,&mpt,p); 93 } 94 __mul(&mps,&mpt,&mpt1,p); 95 __sub(&mps,&mpt1,&mpt,p); 96 97 /* Compute Atan(x) */ 98 mptwoim1.d[1] = twom[m].d; 99 __mul(&mptwoim1,&mpt,y,p); 100 101 return; 102 } 103