1
2/*
3 * IBM Accurate Mathematical Library
4 * written by International Business Machines Corp.
5 * Copyright (C) 2001 Free Software Foundation
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21/******************************************************************/
22/*  MODULE_NAME: mpatan2.c                                        */
23/*                                                                */
24/*  FUNCTIONS:mpatan2                                             */
25/*                                                                */
26/*  FILES NEEDED: mpa.h                                           */
27/*                mpa.c mpatan.c mpsqrt.c                         */
28/*                                                                */
29/* Multi-Precision Atan2(y,x) function subroutine,                */
30/* for precision p >= 4.                                          */
31/* y=0 is not permitted if x<=0. No error messages are given.     */
32/* The relative error of the result is bounded by 44.84*r**(1-p)  */
33/* if x <= 0,  y != 0 and by 37.33*r**(1-p) if x>0. here r=2**24. */
34/*                                                                */
35/******************************************************************/
36
37
38
39#include "mpa.h"
40
41void __mpsqrt(mp_no *, mp_no *, int);
42void __mpatan(mp_no *, mp_no *, int);
43
44/* Multi-Precision Atan2(y,x) function subroutine, for p >= 4.    */
45/* y=0 is not permitted if x<=0. No error messages are given.     */
46void __mpatan2(mp_no *y, mp_no *x, mp_no *z, int p) {
47
48  static const double ZERO = 0.0, ONE = 1.0;
49
50  mp_no mpone = {0,{0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
51                    0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,
52                    0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0}};
53  mp_no mpt1,mpt2,mpt3;
54
55
56  if (X[0] <= ZERO) {
57    mpone.e = 1;                 mpone.d[0] = mpone.d[1] = ONE;
58    __dvd(x,y,&mpt1,p);          __mul(&mpt1,&mpt1,&mpt2,p);
59    if (mpt1.d[0] != ZERO)       mpt1.d[0] = ONE;
60    __add(&mpt2,&mpone,&mpt3,p); __mpsqrt(&mpt3,&mpt2,p);
61    __add(&mpt1,&mpt2,&mpt3,p);  mpt3.d[0]=Y[0];
62    __mpatan(&mpt3,&mpt1,p);     __add(&mpt1,&mpt1,z,p);
63  }
64  else
65  { __dvd(y,x,&mpt1,p);
66    __mpatan(&mpt1,z,p);
67  }
68
69  return;
70}
71