xref: /haiku/src/system/libroot/posix/glibc/arch/generic/mpa.h (revision 8e17108ffa0f1779de716fa1c3ef503ab12f0aaa)
1*8e17108fSIngo Weinhold 
2*8e17108fSIngo Weinhold /*
3*8e17108fSIngo Weinhold  * IBM Accurate Mathematical Library
4*8e17108fSIngo Weinhold  * Written by International Business Machines Corp.
5*8e17108fSIngo Weinhold  * Copyright (C) 2001 Free Software Foundation, Inc.
6*8e17108fSIngo Weinhold  *
7*8e17108fSIngo Weinhold  * This program is free software; you can redistribute it and/or modify
8*8e17108fSIngo Weinhold  * it under the terms of the GNU Lesser General Public License as published by
9*8e17108fSIngo Weinhold  * the Free Software Foundation; either version 2.1 of the License, or
10*8e17108fSIngo Weinhold  * (at your option) any later version.
11*8e17108fSIngo Weinhold  *
12*8e17108fSIngo Weinhold  * This program is distributed in the hope that it will be useful,
13*8e17108fSIngo Weinhold  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14*8e17108fSIngo Weinhold  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15*8e17108fSIngo Weinhold  * GNU Lesser General Public License for more details.
16*8e17108fSIngo Weinhold  *
17*8e17108fSIngo Weinhold  * You should have received a copy of the GNU Lesser General Public License
18*8e17108fSIngo Weinhold  * along with this program; if not, write to the Free Software
19*8e17108fSIngo Weinhold  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20*8e17108fSIngo Weinhold  */
21*8e17108fSIngo Weinhold 
22*8e17108fSIngo Weinhold /************************************************************************/
23*8e17108fSIngo Weinhold /*  MODULE_NAME: mpa.h                                                  */
24*8e17108fSIngo Weinhold /*                                                                      */
25*8e17108fSIngo Weinhold /*  FUNCTIONS:                                                          */
26*8e17108fSIngo Weinhold /*               mcr                                                    */
27*8e17108fSIngo Weinhold /*               acr                                                    */
28*8e17108fSIngo Weinhold /*               cr                                                     */
29*8e17108fSIngo Weinhold /*               cpy                                                    */
30*8e17108fSIngo Weinhold /*               cpymn                                                  */
31*8e17108fSIngo Weinhold /*               mp_dbl                                                 */
32*8e17108fSIngo Weinhold /*               dbl_mp                                                 */
33*8e17108fSIngo Weinhold /*               add                                                    */
34*8e17108fSIngo Weinhold /*               sub                                                    */
35*8e17108fSIngo Weinhold /*               mul                                                    */
36*8e17108fSIngo Weinhold /*               inv                                                    */
37*8e17108fSIngo Weinhold /*               dvd                                                    */
38*8e17108fSIngo Weinhold /*                                                                      */
39*8e17108fSIngo Weinhold /* Arithmetic functions for multiple precision numbers.                 */
40*8e17108fSIngo Weinhold /* Common types and definition                                          */
41*8e17108fSIngo Weinhold /************************************************************************/
42*8e17108fSIngo Weinhold 
43*8e17108fSIngo Weinhold 
44*8e17108fSIngo Weinhold typedef struct {/* This structure holds the details of a multi-precision     */
45*8e17108fSIngo Weinhold   int e;        /* floating point number, x: d[0] holds its sign (-1,0 or 1) */
46*8e17108fSIngo Weinhold   double d[40]; /* e holds its exponent (...,-2,-1,0,1,2,...) and            */
47*8e17108fSIngo Weinhold } mp_no;        /* d[1]...d[p] hold its mantissa digits. The value of x is,  */
48*8e17108fSIngo Weinhold                 /* x = d[1]*r**(e-1) + d[2]*r**(e-2) + ... + d[p]*r**(e-p).  */
49*8e17108fSIngo Weinhold                 /* Here   r = 2**24,   0 <= d[i] < r  and  1 <= p <= 32.     */
50*8e17108fSIngo Weinhold                 /* p is a global variable. A multi-precision number is       */
51*8e17108fSIngo Weinhold                 /* always normalized. Namely, d[1] > 0. An exception is      */
52*8e17108fSIngo Weinhold                 /* a zero which is characterized by d[0] = 0. The terms      */
53*8e17108fSIngo Weinhold                 /* d[p+1], d[p+2], ... of a none zero number have no         */
54*8e17108fSIngo Weinhold                 /* significance and so are the terms e, d[1],d[2],...        */
55*8e17108fSIngo Weinhold                 /* of a zero.                                                */
56*8e17108fSIngo Weinhold 
57*8e17108fSIngo Weinhold typedef union { int i[2]; double d; } number;
58*8e17108fSIngo Weinhold 
59*8e17108fSIngo Weinhold #define  X   x->d
60*8e17108fSIngo Weinhold #define  Y   y->d
61*8e17108fSIngo Weinhold #define  Z   z->d
62*8e17108fSIngo Weinhold #define  EX  x->e
63*8e17108fSIngo Weinhold #define  EY  y->e
64*8e17108fSIngo Weinhold #define  EZ  z->e
65*8e17108fSIngo Weinhold 
66*8e17108fSIngo Weinhold #define MAX(x,y) ((x) < (y) ?  (y) : (x))
67*8e17108fSIngo Weinhold #define MIN(x,y) ((x) < (y) ?  (x) : (y))
68*8e17108fSIngo Weinhold #define ABS(x)   ((x) <  0  ? -(x) : (x))
69*8e17108fSIngo Weinhold 
70*8e17108fSIngo Weinhold int __acr(const mp_no *, const mp_no *, int);
71*8e17108fSIngo Weinhold int  __cr(const mp_no *, const mp_no *, int);
72*8e17108fSIngo Weinhold void __cpy(const mp_no *, mp_no *, int);
73*8e17108fSIngo Weinhold void __cpymn(const mp_no *, int, mp_no *, int);
74*8e17108fSIngo Weinhold void __mp_dbl(const mp_no *, double *, int);
75*8e17108fSIngo Weinhold void __dbl_mp(double, mp_no *, int);
76*8e17108fSIngo Weinhold void __add(const mp_no *, const mp_no *, mp_no *, int);
77*8e17108fSIngo Weinhold void __sub(const mp_no *, const mp_no *, mp_no *, int);
78*8e17108fSIngo Weinhold void __mul(const mp_no *, const mp_no *, mp_no *, int);
79*8e17108fSIngo Weinhold void __inv(const mp_no *, mp_no *, int);
80*8e17108fSIngo Weinhold void __dvd(const mp_no *, const mp_no *, mp_no *, int);
81*8e17108fSIngo Weinhold 
82*8e17108fSIngo Weinhold extern void __mpatan (mp_no *, mp_no *, int);
83*8e17108fSIngo Weinhold extern void __mpatan2 (mp_no *, mp_no *, mp_no *, int);
84*8e17108fSIngo Weinhold extern void __mpsqrt (mp_no *, mp_no *, int);
85*8e17108fSIngo Weinhold extern void __mpexp (mp_no *, mp_no *__y, int);
86*8e17108fSIngo Weinhold extern void __c32 (mp_no *, mp_no *, mp_no *, int);
87*8e17108fSIngo Weinhold extern int __mpranred (double, mp_no *, int);
88