Back to index

glibc  2.9
mptan.c
Go to the documentation of this file.
00001 
00002 /*
00003  * IBM Accurate Mathematical Library
00004  * written by International Business Machines Corp.
00005  * Copyright (C) 2001 Free Software Foundation
00006  *
00007  * This program is free software; you can redistribute it and/or modify
00008  * it under the terms of the GNU Lesser General Public License as published by
00009  * the Free Software Foundation; either version 2.1 of the License, or
00010  * (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00020  */
00021 /**********************************************************************/
00022 /* MODULE_NAME:mptan.c                                                */
00023 /*                                                                    */
00024 /* FUNCTION: mptan                                                    */
00025 /*                                                                    */
00026 /* FILES NEEDED: endian.h  mpa.h                                      */
00027 /*               mpa.c  sincos32.c branred.c                          */
00028 /*                                                                    */
00029 /* Multi-Precision tan() function subroutine, for p=32.  It is based  */
00030 /* on the routines mpranred() and c32(). mpranred() performs range    */
00031 /* reduction of a double number x into a multiple precision number    */
00032 /* y, such that y=x-n*pi/2, abs(y)<pi/4, n=0,+-1,+-2,....  c32()      */
00033 /* computes both sin(y), cos(y).  tan(x) is either sin(y)/cos(y)      */
00034 /* or -cos(y)/sin(y). The precision of the result is of about 559     */
00035 /* significant bits.                                                  */
00036 /*                                                                    */
00037 /**********************************************************************/
00038 #include "endian.h"
00039 #include "mpa.h"
00040 
00041 int __mpranred(double, mp_no *, int);
00042 void __c32(mp_no *, mp_no *, mp_no *, int);
00043 
00044 void __mptan(double x, mp_no *mpy, int p) {
00045 
00046   static const double MONE = -1.0;
00047 
00048   int n;
00049   mp_no mpw, mpc, mps;
00050 
00051   n = __mpranred(x, &mpw, p) & 0x00000001; /* negative or positive result */
00052   __c32(&mpw, &mpc, &mps, p);              /* computing sin(x) and cos(x) */
00053   if (n)                     /* second or fourth quarter of unit circle */
00054   { __dvd(&mpc,&mps,mpy,p);
00055     mpy->d[0] *= MONE;
00056   }                          /* tan is negative in this area */
00057   else  __dvd(&mps,&mpc,mpy,p);
00058 
00059   return;
00060 }