Blame sysdeps/ieee754/dbl-64/mptan.c

Packit 6c4009
/*
Packit 6c4009
 * IBM Accurate Mathematical Library
Packit 6c4009
 * written by International Business Machines Corp.
Packit 6c4009
 * Copyright (C) 2001-2018 Free Software Foundation, Inc.
Packit 6c4009
 *
Packit 6c4009
 * This program is free software; you can redistribute it and/or modify
Packit 6c4009
 * it under the terms of the GNU Lesser General Public License as published by
Packit 6c4009
 * the Free Software Foundation; either version 2.1 of the License, or
Packit 6c4009
 * (at your option) any later version.
Packit 6c4009
 *
Packit 6c4009
 * This program is distributed in the hope that it will be useful,
Packit 6c4009
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit 6c4009
 * GNU Lesser General Public License for more details.
Packit 6c4009
 *
Packit 6c4009
 * You should have received a copy of the GNU Lesser General Public License
Packit 6c4009
 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Packit 6c4009
 */
Packit 6c4009
/**********************************************************************/
Packit 6c4009
/* MODULE_NAME:mptan.c                                                */
Packit 6c4009
/*                                                                    */
Packit 6c4009
/* FUNCTION: mptan                                                    */
Packit 6c4009
/*                                                                    */
Packit 6c4009
/* FILES NEEDED: endian.h  mpa.h                                      */
Packit 6c4009
/*               mpa.c  sincos32.c branred.c                          */
Packit 6c4009
/*                                                                    */
Packit 6c4009
/* Multi-Precision tan() function subroutine, for p=32.  It is based  */
Packit 6c4009
/* on the routines mpranred() and c32(). mpranred() performs range    */
Packit 6c4009
/* reduction of a double number x into a multiple precision number    */
Packit 6c4009
/* y, such that y=x-n*pi/2, abs(y)
Packit 6c4009
/* computes both sin(y), cos(y).  tan(x) is either sin(y)/cos(y)      */
Packit 6c4009
/* or -cos(y)/sin(y). The precision of the result is of about 559     */
Packit 6c4009
/* significant bits.                                                  */
Packit 6c4009
/*                                                                    */
Packit 6c4009
/**********************************************************************/
Packit 6c4009
#include "endian.h"
Packit 6c4009
#include "mpa.h"
Packit 6c4009
Packit 6c4009
#ifndef SECTION
Packit 6c4009
# define SECTION
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
void
Packit 6c4009
SECTION
Packit 6c4009
__mptan (double x, mp_no *mpy, int p)
Packit 6c4009
{
Packit 6c4009
  int n;
Packit 6c4009
  mp_no mpw, mpc, mps;
Packit 6c4009
Packit 6c4009
  /* Negative or positive result.  */
Packit 6c4009
  n = __mpranred (x, &mpw, p) & 0x00000001;
Packit 6c4009
  /* Computing sin(x) and cos(x).  */
Packit 6c4009
  __c32 (&mpw, &mpc, &mps, p);
Packit 6c4009
  /* Second or fourth quarter of unit circle.  */
Packit 6c4009
  if (n)
Packit 6c4009
    {
Packit 6c4009
      __dvd (&mpc, &mps, mpy, p);
Packit 6c4009
      mpy->d[0] *= -1;
Packit 6c4009
    }
Packit 6c4009
  /* tan is negative in this area.  */
Packit 6c4009
  else
Packit 6c4009
    __dvd (&mps, &mpc, mpy, p);
Packit 6c4009
}