2 * IBM Accurate Mathematical Library
3 * Written by International Business Machines Corp.
4 * Copyright (C) 2001-2016 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, see <http://www.gnu.org/licenses/>.
19 /*******************************************************************/
21 /* MODULE_NAME: branred.c */
23 /* FUNCTIONS: branred */
25 /* FILES NEEDED: branred.h mydefs.h endian.h mpa.h */
28 /* Routine branred() performs range reduction of a double number */
29 /* x into Double length number a+aa,such that */
30 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,.... */
31 /* Routine returns the integer (n mod 4) of the above description */
33 /*******************************************************************/
39 #include <math_private.h>
46 /*******************************************************************/
47 /* Routine branred() performs range reduction of a double number */
48 /* x into Double length number a+aa,such that */
49 /* x=n*pi/2+(a+aa), abs(a+aa)<pi/4, n=0,+-1,+-2,.... */
50 /* Routine return integer (n mod 4) */
51 /*******************************************************************/
54 __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
= (fabs(b1
)>fabs(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 */