2 * IBM Accurate Mathematical Library
3 * Written by International Business Machines Corp.
4 * Copyright (C) 2001 Free Software Foundation, Inc.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 /*******************************************************************/
22 /* MODULE_NAME: branred.c */
24 /* FUNCTIONS: branred */
26 /* FILES NEEDED: branred.h mydefs.h endian.h mpa.h */
29 /* Routine branred() performs range reduction of a double number */
30 /* x into Double length number a+aa,such that */
31 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,.... */
32 /* Routine returns the integer (n mod 4) of the above description */
34 /*******************************************************************/
39 #include "math_private.h"
42 /*******************************************************************/
43 /* Routine branred() performs range reduction of a double number */
44 /* x into Double length number a+aa,such that */
45 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,.... */
46 /* Routine return integer (n mod 4) */
47 /*******************************************************************/
48 int __branred(double x, double *a, double *aa)
58 double r[6],s,t,sum,b,bb,sum1,sum2,b1,bb1,b2,bb2,x1,x2,t1,t2;
61 t=x*split; /* split x to two numbers */
66 k = (u.i[HIGH_HALF]>>20)&2047;
71 gor.i[HIGH_HALF] -= ((k*24)<<20);
73 { r[i] = x1*toverp[k+i]*gor.x; gor.x *= tm24.x; }
82 bb=(((((r[0]-t)+r[1])+r[2])+r[3])+r[4])+r[5];
88 s=(sum+big1.x)-big1.x;
96 k = (u.i[HIGH_HALF]>>20)&2047;
101 gor.i[HIGH_HALF] -= ((k*24)<<20);
103 { r[i] = x2*toverp[k+i]*gor.x; gor.x *= tm24.x; }
105 s=(r[i]+big.x)-big.x;
112 bb=(((((r[0]-t)+r[1])+r[2])+r[3])+r[4])+r[5];
118 s=(sum+big1.x)-big1.x;
127 bb = (ABS(b1)>ABS(b2))? (b1-b)+b2 : (b2-b)+b1;
133 t=((b-s)+bb)+(bb1+bb2);
138 bb=(((t1*mp1.x-b)+t1*mp2.x)+t2*mp1.x)+(t2*mp2.x+s*hp1.x+t*hp0.x);
143 return ((int) sum)&3; /* return quater of unit circle */