Back to index

glibc  2.9
branred.c
Go to the documentation of this file.
00001 /*
00002  * IBM Accurate Mathematical Library
00003  * Written by International Business Machines Corp.
00004  * Copyright (C) 2001 Free Software Foundation, Inc.
00005  *
00006  * This program is free software; you can redistribute it and/or modify
00007  * it under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 2.1 of the License, or
00009  * (at your option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU Lesser General Public License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00019  */
00020 /*******************************************************************/
00021 /*                                                                 */
00022 /* MODULE_NAME: branred.c                                          */
00023 /*                                                                 */
00024 /* FUNCTIONS:   branred                                            */
00025 /*                                                                 */
00026 /* FILES NEEDED: branred.h mydefs.h endian.h mpa.h                 */
00027 /*               mha.c                                             */
00028 /*                                                                 */
00029 /* Routine  branred() performs range  reduction of a double number */
00030 /* x into Double length number  a+aa,such that                     */
00031 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,....               */
00032 /* Routine returns the integer (n mod 4) of the above description  */
00033 /* of x.                                                           */
00034 /*******************************************************************/
00035 
00036 #include "endian.h"
00037 #include "mydefs.h"
00038 #include "branred.h"
00039 #include "math_private.h"
00040 
00041 
00042 /*******************************************************************/
00043 /* Routine  branred() performs range  reduction of a double number */
00044 /* x into Double length number a+aa,such that                      */
00045 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,....               */
00046 /* Routine return integer (n mod 4)                                */
00047 /*******************************************************************/
00048 int __branred(double x, double *a, double *aa)
00049 {
00050   int i,k;
00051 #if 0
00052   int n;
00053 #endif
00054   mynumber  u,gor;
00055 #if 0
00056   mynumber v;
00057 #endif
00058   double r[6],s,t,sum,b,bb,sum1,sum2,b1,bb1,b2,bb2,x1,x2,t1,t2;
00059 
00060   x*=tm600.x;
00061   t=x*split;   /* split x to two numbers */
00062   x1=t-(t-x);
00063   x2=x-x1;
00064   sum=0;
00065   u.x = x1;
00066   k = (u.i[HIGH_HALF]>>20)&2047;
00067   k = (k-450)/24;
00068   if (k<0)
00069     k=0;
00070   gor.x = t576.x;
00071   gor.i[HIGH_HALF] -= ((k*24)<<20);
00072   for (i=0;i<6;i++)
00073     { r[i] = x1*toverp[k+i]*gor.x; gor.x *= tm24.x; }
00074   for (i=0;i<3;i++) {
00075     s=(r[i]+big.x)-big.x;
00076     sum+=s;
00077     r[i]-=s;
00078   }
00079   t=0;
00080   for (i=0;i<6;i++)
00081     t+=r[5-i];
00082   bb=(((((r[0]-t)+r[1])+r[2])+r[3])+r[4])+r[5];
00083   s=(t+big.x)-big.x;
00084   sum+=s;
00085   t-=s;
00086   b=t+bb;
00087   bb=(t-b)+bb;
00088   s=(sum+big1.x)-big1.x;
00089   sum-=s;
00090   b1=b;
00091   bb1=bb;
00092   sum1=sum;
00093   sum=0;
00094 
00095   u.x = x2;
00096   k = (u.i[HIGH_HALF]>>20)&2047;
00097   k = (k-450)/24;
00098   if (k<0)
00099     k=0;
00100   gor.x = t576.x;
00101   gor.i[HIGH_HALF] -= ((k*24)<<20);
00102   for (i=0;i<6;i++)
00103     { r[i] = x2*toverp[k+i]*gor.x; gor.x *= tm24.x; }
00104   for (i=0;i<3;i++) {
00105     s=(r[i]+big.x)-big.x;
00106     sum+=s;
00107     r[i]-=s;
00108   }
00109   t=0;
00110   for (i=0;i<6;i++)
00111     t+=r[5-i];
00112   bb=(((((r[0]-t)+r[1])+r[2])+r[3])+r[4])+r[5];
00113   s=(t+big.x)-big.x;
00114  sum+=s;
00115  t-=s;
00116  b=t+bb;
00117  bb=(t-b)+bb;
00118  s=(sum+big1.x)-big1.x;
00119  sum-=s;
00120 
00121  b2=b;
00122  bb2=bb;
00123  sum2=sum;
00124 
00125  sum=sum1+sum2;
00126  b=b1+b2;
00127  bb = (ABS(b1)>ABS(b2))? (b1-b)+b2 : (b2-b)+b1;
00128  if (b > 0.5)
00129    {b-=1.0; sum+=1.0;}
00130  else if (b < -0.5)
00131    {b+=1.0; sum-=1.0;}
00132  s=b+(bb+bb1+bb2);
00133  t=((b-s)+bb)+(bb1+bb2);
00134  b=s*split;
00135  t1=b-(b-s);
00136  t2=s-t1;
00137  b=s*hp0.x;
00138  bb=(((t1*mp1.x-b)+t1*mp2.x)+t2*mp1.x)+(t2*mp2.x+s*hp1.x+t*hp0.x);
00139  s=b+bb;
00140  t=(b-s)+bb;
00141  *a=s;
00142  *aa=t;
00143  return ((int) sum)&3; /* return quater of unit circle */
00144 }