1 /****************************************************************
3 * The author of this software is David M. Gay.
5 * Copyright (c) 1991, 2000 by AT&T.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose without fee is hereby granted, provided that this entire notice
9 * is included in all copies of any software which is or includes a copy
10 * or modification of this software and in all copies of the supporting
11 * documentation for such software.
13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
14 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHOR NOR AT&T MAKES ANY
15 * REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING THE MERCHANTABILITY
16 * OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
18 ***************************************************************/
20 /* Please send bug reports to
22 AT&T Bell Laboratories, Room 2C-463
24 Murray Hill, NJ 07974-2070
26 dmg@research.att.com or research!dmg
29 #ifndef __CLASSPATH_MPREC_H__
30 #define __CLASSPATH_MPREC_H__
33 /* #include "config-int.h" */
37 /* #include "namespace.h" */
39 #if defined HAVE_SYS_TYPES_H
40 #include <sys/types.h>
43 #if defined HAVE_SYS_CONFIG_H
44 #include <sys/config.h>
51 /* These typedefs are true for the targets running Java. */
53 #ifdef __IEEE_LITTLE_ENDIAN
57 #ifdef __IEEE_BIG_ENDIAN
68 #define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
72 #ifdef Unsigned_Shifts
73 #define Sign_Extend(a,b) if (b < 0) a |= (uint32_t)0xffff0000;
75 #define Sign_Extend(a,b) /*no-op*/
78 #if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
79 Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
82 /* If we are going to examine or modify specific bits in a double using
83 the word0 and/or word1 macros, then we must wrap the double inside
84 a union. This is necessary to avoid undefined behavior according to
93 #define word0(x) (x.i[1])
94 #define word1(x) (x.i[0])
96 #define word0(x) (x.i[0])
97 #define word1(x) (x.i[1])
100 /* The following definition of Storeinc is appropriate for MIPS processors.
101 * An alternative that might be better on some machines is
102 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
104 #if defined(__IEEE_BYTES_LITTLE_ENDIAN) + defined(IEEE_8087) + defined(VAX)
105 #define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
106 ((unsigned short *)a)[0] = (unsigned short)c, a++)
108 #define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
109 ((unsigned short *)a)[1] = (unsigned short)c, a++)
112 /* #define P DBL_MANT_DIG */
113 /* Ten_pmax = floor(P*log(2)/log(5)) */
114 /* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
115 /* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
116 /* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
118 #if defined(IEEE_8087) + defined(IEEE_MC68k)
119 #if defined (_DOUBLE_IS_32BITS)
121 #define Exp_shift1 23
122 #define Exp_msk1 ((uint32_t)0x00800000L)
123 #define Exp_msk11 ((uint32_t)0x00800000L)
124 #define Exp_mask ((uint32_t)0x7f800000L)
128 #define IEEE_Arith /* it is, but the code doesn't handle IEEE singles yet */
131 #define Exp_1 ((uint32_t)0x3f800000L)
132 #define Exp_11 ((uint32_t)0x3f800000L)
134 #define Frac_mask ((uint32_t)0x007fffffL)
135 #define Frac_mask1 ((uint32_t)0x007fffffL)
137 #define Sign_bit ((uint32_t)0x80000000L)
140 #define Bndry_mask ((uint32_t)0x007fffffL)
141 #define Bndry_mask1 ((uint32_t)0x007fffffL)
143 #define Sign_bit ((uint32_t)0x80000000L)
149 #define Infinite(x) (word0(x) == ((uint32_t)0x7f800000L))
153 #define word0(x) (x.i[0])
158 #define Exp_shift1 20
159 #define Exp_msk1 ((uint32_t)0x100000L)
160 #define Exp_msk11 ((uint32_t)0x100000L)
161 #define Exp_mask ((uint32_t)0x7ff00000L)
166 #define Exp_1 ((uint32_t)0x3ff00000L)
167 #define Exp_11 ((uint32_t)0x3ff00000L)
169 #define Frac_mask ((uint32_t)0xfffffL)
170 #define Frac_mask1 ((uint32_t)0xfffffL)
173 #define Bndry_mask ((uint32_t)0xfffffL)
174 #define Bndry_mask1 ((uint32_t)0xfffffL)
176 #define Sign_bit ((uint32_t)0x80000000L)
182 #define Infinite(x) (word0(x) == ((uint32_t)0x7ff00000L)) /* sufficient test for here */
186 #undef Sudden_Underflow
187 #define Sudden_Underflow
190 #define Exp_shift1 24
191 #define Exp_msk1 ((uint32_t)0x1000000L)
192 #define Exp_msk11 ((uint32_t)0x1000000L)
193 #define Exp_mask ((uint32_t)0x7f000000L)
196 #define Exp_1 ((uint32_t)0x41000000L)
197 #define Exp_11 ((uint32_t)0x41000000L)
198 #define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
199 #define Frac_mask ((uint32_t)0xffffffL)
200 #define Frac_mask1 ((uint32_t)0xffffffL)
203 #define Bndry_mask ((uint32_t)0xefffffL)
204 #define Bndry_mask1 ((uint32_t)0xffffffL)
206 #define Sign_bit ((uint32_t)0x80000000L)
208 #define Tiny0 ((uint32_t)0x100000L)
215 #define Exp_msk1 0x80
216 #define Exp_msk11 ((uint32_t)0x800000L)
217 #define Exp_mask ((uint32_t)0x7f80L)
220 #define Exp_1 ((uint32_t)0x40800000L)
221 #define Exp_11 ((uint32_t)0x4080L)
223 #define Frac_mask ((uint32_t)0x7fffffL)
224 #define Frac_mask1 ((uint32_t)0xffff007fL)
227 #define Bndry_mask ((uint32_t)0xffff007fL)
228 #define Bndry_mask1 ((uint32_t)0xffff007fL)
229 #define LSB ((uint32_t)0x10000L)
230 #define Sign_bit ((uint32_t)0x8000L)
244 #define rounded_product(a,b) a = rnd_prod(a, b)
245 #define rounded_quotient(a,b) a = rnd_quot(a, b)
247 extern double rnd_prod(), rnd_quot();
249 extern double rnd_prod(double, double), rnd_quot(double, double);
252 #define rounded_product(a,b) a *= b
253 #define rounded_quotient(a,b) a /= b
256 #define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
257 #define Big1 ((uint32_t)0xffffffffL)
260 /* When Pack_32 is not defined, we store 16 bits per 32-bit long.
261 * This makes some inner loops simpler and sometimes saves work
262 * during multiplications, but it often seems to make things slightly
263 * slower. Hence the default is now to store 32 bits per long.
267 #if SIZEOF_VOID_P != 8
274 #define MAX_BIGNUMS 16
276 #define MAX_BIGNUM_WDS 32
278 /* Note that this is a workaround for */
279 #define MAX_BIGNUM_WDS 128
284 struct _Jv_Bigint *_next;
285 int _k, _maxwds, _sign, _wds;
294 #define _VOLATILE volatile
295 #define _SIGNED signed
298 #define _EXFUN(name, proto) name proto
299 #define _DEFUN(name, arglist, args) name(args)
300 #define _DEFUN_VOID(name) name(_NOARGS)
301 #define _CAST_VOID (void)
306 /* local copy of errno */
309 /* used by mprec routines */
310 struct _Jv_Bigint *_result;
312 struct _Jv_Bigint *_p5s;
314 struct _Jv_Bigint **_freelist;
319 typedef struct _Jv_Bigint _Jv_Bigint;
321 #define Balloc _Jv_Balloc
322 #define Bfree _Jv_Bfree
323 #define multadd _Jv_multadd
325 #define lo0bits _Jv_lo0bits
326 #define hi0bits _Jv_hi0bits
328 #define mult _Jv_mult
329 #define pow5mult _Jv_pow5mult
330 #define lshift _Jv_lshift
331 #define cmp _Jv__mcmp
332 #define diff _Jv__mdiff
336 #define ratio _Jv_ratio
338 #define tens _Jv__mprec_tens
339 #define bigtens _Jv__mprec_bigtens
340 #define tinytens _Jv__mprec_tinytens
342 #define _dtoa _Jv_dtoa
343 #define _dtoa_r _Jv_dtoa_r
344 #define _strtod_r _Jv_strtod_r
346 extern double _EXFUN(_strtod_r, (struct _Jv_reent *ptr, const char *s00, char **se));
347 extern char* _EXFUN(_dtoa_r, (struct _Jv_reent *ptr, double d,
348 int mode, int ndigits, int *decpt, int *sign,
349 char **rve, int float_type));
350 void _EXFUN(_dtoa, (double d, int mode, int ndigits, int *decpt, int *sign,
351 char **rve, char *buf, int float_type));
353 double _EXFUN(ulp,(double x));
354 double _EXFUN(b2d,(_Jv_Bigint *a , int *e));
355 _Jv_Bigint * _EXFUN(Balloc,(struct _Jv_reent *p, int k));
356 void _EXFUN(Bfree,(struct _Jv_reent *p, _Jv_Bigint *v));
357 _Jv_Bigint * _EXFUN(multadd,(struct _Jv_reent *p, _Jv_Bigint *, int, int));
358 _Jv_Bigint * _EXFUN(s2b,(struct _Jv_reent *, const char*, int, int, unsigned long));
359 _Jv_Bigint * _EXFUN(i2b,(struct _Jv_reent *,int));
360 _Jv_Bigint * _EXFUN(mult, (struct _Jv_reent *, _Jv_Bigint *, _Jv_Bigint *));
361 _Jv_Bigint * _EXFUN(pow5mult, (struct _Jv_reent *, _Jv_Bigint *, int k));
362 int _EXFUN(hi0bits,(unsigned long));
363 int _EXFUN(lo0bits,(unsigned long *));
364 _Jv_Bigint * _EXFUN(d2b,(struct _Jv_reent *p, double d, int *e, int *bits));
365 _Jv_Bigint * _EXFUN(lshift,(struct _Jv_reent *p, _Jv_Bigint *b, int k));
366 _Jv_Bigint * _EXFUN(diff,(struct _Jv_reent *p, _Jv_Bigint *a, _Jv_Bigint *b));
367 int _EXFUN(cmp,(_Jv_Bigint *a, _Jv_Bigint *b));
369 double _EXFUN(ratio,(_Jv_Bigint *a, _Jv_Bigint *b));
370 #define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(long) + 2*sizeof(int))
372 #if defined(_DOUBLE_IS_32BITS) && defined(__v800)
378 extern _CONST double tinytens[];
379 extern _CONST double bigtens[];
380 extern _CONST double tens[];
386 #endif /* __CLASSPATH_MPREC_H__ */