OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [newlib/] [newlib/] [libc/] [stdlib/] [mprec.h] - Blame information for rev 57

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 39 lampret
/****************************************************************
2
 *
3
 * The author of this software is David M. Gay.
4
 *
5
 * Copyright (c) 1991 by AT&T.
6
 *
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.
12
 *
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.
17
 *
18
 ***************************************************************/
19
 
20
/* Please send bug reports to
21
        David M. Gay
22
        AT&T Bell Laboratories, Room 2C-463
23
        600 Mountain Avenue
24
        Murray Hill, NJ 07974-2070
25
        U.S.A.
26
        dmg@research.att.com or research!dmg
27
 */
28
 
29
#include <ieeefp.h>
30
#include <math.h>
31
#include <float.h>
32
#include <errno.h>
33
#include <sys/config.h>
34
 
35
#ifdef __IEEE_LITTLE_ENDIAN
36
#define IEEE_8087
37
#endif
38
 
39
#ifdef __IEEE_BIG_ENDIAN
40
#define IEEE_MC68k
41
#endif
42
 
43
#ifdef __Z8000__
44
#define Just_16
45
#endif
46
 
47
#ifdef DEBUG
48
#include "stdio.h"
49
#define Bug(x) {fprintf(stderr, "%s\n", x); exit(1);}
50
#endif
51
 
52
#ifdef Unsigned_Shifts
53
#define Sign_Extend(a,b) if (b < 0) a |= (__uint32_t)0xffff0000;
54
#else
55
#define Sign_Extend(a,b) /*no-op*/
56
#endif
57
 
58
#if defined(IEEE_8087) + defined(IEEE_MC68k) + defined(VAX) + defined(IBM) != 1
59
Exactly one of IEEE_8087, IEEE_MC68k, VAX, or IBM should be defined.
60
#endif
61
 
62
/* If we are going to examine or modify specific bits in a double using
63
   the word0 and/or word1 macros, then we must wrap the double inside
64
   a union.  This is necessary to avoid undefined behavior according to
65
   the ANSI C spec.  */
66
union double_union
67
{
68
  double d;
69
  __uint32_t i[2];
70
};
71
 
72
#ifdef IEEE_8087
73
#define word0(x) (x.i[1])
74
#define word1(x) (x.i[0])
75
#else
76
#define word0(x) (x.i[0])
77
#define word1(x) (x.i[1])
78
#endif
79
 
80
/* The following definition of Storeinc is appropriate for MIPS processors.
81
 * An alternative that might be better on some machines is
82
 * #define Storeinc(a,b,c) (*a++ = b << 16 | c & 0xffff)
83
 */
84
#if defined(IEEE_8087) + defined(VAX)
85
#define Storeinc(a,b,c) (((unsigned short *)a)[1] = (unsigned short)b, \
86
((unsigned short *)a)[0] = (unsigned short)c, a++)
87
#else
88
#define Storeinc(a,b,c) (((unsigned short *)a)[0] = (unsigned short)b, \
89
((unsigned short *)a)[1] = (unsigned short)c, a++)
90
#endif
91
 
92
/* #define P DBL_MANT_DIG */
93
/* Ten_pmax = floor(P*log(2)/log(5)) */
94
/* Bletch = (highest power of 2 < DBL_MAX_10_EXP) / 16 */
95
/* Quick_max = floor((P-1)*log(FLT_RADIX)/log(10) - 1) */
96
/* Int_max = floor(P*log(FLT_RADIX)/log(10) - 1) */
97
 
98
#if defined(IEEE_8087) + defined(IEEE_MC68k)
99
#if defined (_DOUBLE_IS_32BITS) 
100
#define Exp_shift   23
101
#define Exp_shift1  23
102
#define Exp_msk1    ((__uint32_t)0x00800000L)
103
#define Exp_msk11   ((__uint32_t)0x00800000L)
104
#define Exp_mask    ((__uint32_t)0x7f800000L)
105
#define P           24
106
#define Bias        127
107
#if 0
108
#define IEEE_Arith  /* it is, but the code doesn't handle IEEE singles yet */
109
#endif
110
#define Emin        (-126)
111
#define Exp_1       ((__uint32_t)0x3f800000L)
112
#define Exp_11      ((__uint32_t)0x3f800000L)
113
#define Ebits       8
114
#define Frac_mask   ((__uint32_t)0x007fffffL)
115
#define Frac_mask1  ((__uint32_t)0x007fffffL)
116
#define Ten_pmax    10
117
#define Sign_bit    ((__uint32_t)0x80000000L)
118
#define Ten_pmax    10
119
#define Bletch      2
120
#define Bndry_mask  ((__uint32_t)0x007fffffL)
121
#define Bndry_mask1 ((__uint32_t)0x007fffffL)
122
#define LSB 1
123
#define Sign_bit    ((__uint32_t)0x80000000L)
124
#define Log2P       1
125
#define Tiny0       0
126
#define Tiny1       1
127
#define Quick_max   5
128
#define Int_max     6
129
#define Infinite(x) (word0(x) == ((__uint32_t)0x7f800000L))
130
#undef word0
131
#undef word1
132
 
133
#define word0(x) (x.i[0])
134
#define word1(x) 0
135
#else
136
 
137
#define Exp_shift  20
138
#define Exp_shift1 20
139
#define Exp_msk1    ((__uint32_t)0x100000L)
140
#define Exp_msk11   ((__uint32_t)0x100000L)
141
#define Exp_mask  ((__uint32_t)0x7ff00000L)
142
#define P 53
143
#define Bias 1023
144
#define IEEE_Arith
145
#define Emin (-1022)
146
#define Exp_1  ((__uint32_t)0x3ff00000L)
147
#define Exp_11 ((__uint32_t)0x3ff00000L)
148
#define Ebits 11
149
#define Frac_mask  ((__uint32_t)0xfffffL)
150
#define Frac_mask1 ((__uint32_t)0xfffffL)
151
#define Ten_pmax 22
152
#define Bletch 0x10
153
#define Bndry_mask  ((__uint32_t)0xfffffL)
154
#define Bndry_mask1 ((__uint32_t)0xfffffL)
155
#define LSB 1
156
#define Sign_bit ((__uint32_t)0x80000000L)
157
#define Log2P 1
158
#define Tiny0 0
159
#define Tiny1 1
160
#define Quick_max 14
161
#define Int_max 14
162
#define Infinite(x) (word0(x) == ((__uint32_t)0x7ff00000L)) /* sufficient test for here */
163
#endif
164
 
165
#else
166
#undef  Sudden_Underflow
167
#define Sudden_Underflow
168
#ifdef IBM
169
#define Exp_shift  24
170
#define Exp_shift1 24
171
#define Exp_msk1   ((__uint32_t)0x1000000L)
172
#define Exp_msk11  ((__uint32_t)0x1000000L)
173
#define Exp_mask  ((__uint32_t)0x7f000000L)
174
#define P 14
175
#define Bias 65
176
#define Exp_1  ((__uint32_t)0x41000000L)
177
#define Exp_11 ((__uint32_t)0x41000000L)
178
#define Ebits 8 /* exponent has 7 bits, but 8 is the right value in b2d */
179
#define Frac_mask  ((__uint32_t)0xffffffL)
180
#define Frac_mask1 ((__uint32_t)0xffffffL)
181
#define Bletch 4
182
#define Ten_pmax 22
183
#define Bndry_mask  ((__uint32_t)0xefffffL)
184
#define Bndry_mask1 ((__uint32_t)0xffffffL)
185
#define LSB 1
186
#define Sign_bit ((__uint32_t)0x80000000L)
187
#define Log2P 4
188
#define Tiny0 ((__uint32_t)0x100000L)
189
#define Tiny1 0
190
#define Quick_max 14
191
#define Int_max 15
192
#else /* VAX */
193
#define Exp_shift  23
194
#define Exp_shift1 7
195
#define Exp_msk1    0x80
196
#define Exp_msk11   ((__uint32_t)0x800000L)
197
#define Exp_mask  ((__uint32_t)0x7f80L)
198
#define P 56
199
#define Bias 129
200
#define Exp_1  ((__uint32_t)0x40800000L)
201
#define Exp_11 ((__uint32_t)0x4080L)
202
#define Ebits 8
203
#define Frac_mask  ((__uint32_t)0x7fffffL)
204
#define Frac_mask1 ((__uint32_t)0xffff007fL)
205
#define Ten_pmax 24
206
#define Bletch 2
207
#define Bndry_mask  ((__uint32_t)0xffff007fL)
208
#define Bndry_mask1 ((__uint32_t)0xffff007fL)
209
#define LSB ((__uint32_t)0x10000L)
210
#define Sign_bit ((__uint32_t)0x8000L)
211
#define Log2P 1
212
#define Tiny0 0x80
213
#define Tiny1 0
214
#define Quick_max 15
215
#define Int_max 15
216
#endif
217
#endif
218
 
219
#ifndef IEEE_Arith
220
#define ROUND_BIASED
221
#endif
222
 
223
#ifdef RND_PRODQUOT
224
#define rounded_product(a,b) a = rnd_prod(a, b)
225
#define rounded_quotient(a,b) a = rnd_quot(a, b)
226
#ifdef KR_headers
227
extern double rnd_prod(), rnd_quot();
228
#else
229
extern double rnd_prod(double, double), rnd_quot(double, double);
230
#endif
231
#else
232
#define rounded_product(a,b) a *= b
233
#define rounded_quotient(a,b) a /= b
234
#endif
235
 
236
#define Big0 (Frac_mask1 | Exp_msk1*(DBL_MAX_EXP+Bias-1))
237
#define Big1 ((__uint32_t)0xffffffffL)
238
 
239
#ifndef Just_16
240
/* When Pack_32 is not defined, we store 16 bits per 32-bit long.
241
 * This makes some inner loops simpler and sometimes saves work
242
 * during multiplications, but it often seems to make things slightly
243
 * slower.  Hence the default is now to store 32 bits per long.
244
 */
245
 
246
#ifndef Pack_32
247
#define Pack_32
248
#endif
249
#endif
250
 
251
 
252
#ifdef __cplusplus
253
extern "C" double strtod(const char *s00, char **se);
254
extern "C" char *dtoa(double d, int mode, int ndigits,
255
                        int *decpt, int *sign, char **rve);
256
#endif
257
 
258
 
259
typedef struct _Bigint _Bigint;
260
 
261
#define Balloc  _Balloc
262
#define Bfree   _Bfree
263
#define multadd _multadd
264
#define s2b     _s2b
265
#define lo0bits _lo0bits
266
#define hi0bits _hi0bits
267
#define i2b     _i2b
268 56 joel
#define mult    _multiply
269 39 lampret
#define pow5mult        _pow5mult
270
#define lshift  _lshift
271
#define cmp     __mcmp
272
#define diff    __mdiff
273
#define ulp     _ulp
274
#define b2d     _b2d
275
#define d2b     _d2b
276
#define ratio   _ratio
277
 
278
#define tens __mprec_tens
279
#define bigtens __mprec_bigtens
280
#define tinytens __mprec_tinytens
281
 
282
struct _reent ;
283
double          _EXFUN(ulp,(double x));
284
double          _EXFUN(b2d,(_Bigint *a , int *e));
285
_Bigint *       _EXFUN(Balloc,(struct _reent *p, int k));
286
void            _EXFUN(Bfree,(struct _reent *p, _Bigint *v));
287
_Bigint *       _EXFUN(multadd,(struct _reent *p, _Bigint *, int, int));
288 56 joel
_Bigint *       _EXFUN(s2b,(struct _reent *, const char*, int, int, __ULong));
289 39 lampret
_Bigint *       _EXFUN(i2b,(struct _reent *,int));
290
_Bigint *       _EXFUN(mult, (struct _reent *, _Bigint *, _Bigint *));
291
_Bigint *       _EXFUN(pow5mult, (struct _reent *, _Bigint *, int k));
292 56 joel
int             _EXFUN(hi0bits,(__ULong));
293
int             _EXFUN(lo0bits,(__ULong *));
294 39 lampret
_Bigint *        _EXFUN(d2b,(struct _reent *p, double d, int *e, int *bits));
295
_Bigint *        _EXFUN(lshift,(struct _reent *p, _Bigint *b, int k));
296
_Bigint *        _EXFUN(diff,(struct _reent *p, _Bigint *a, _Bigint *b));
297
int             _EXFUN(cmp,(_Bigint *a, _Bigint *b));
298
 
299
double          _EXFUN(ratio,(_Bigint *a, _Bigint *b));
300 56 joel
#define Bcopy(x,y) memcpy((char *)&x->_sign, (char *)&y->_sign, y->_wds*sizeof(__Long) + 2*sizeof(int))
301 39 lampret
 
302
#if defined(_DOUBLE_IS_32BITS) && defined(__v800)
303
#define n_bigtens 2
304
#else
305
#define n_bigtens 5
306
#endif
307
 
308
extern _CONST double tinytens[];
309
extern _CONST double bigtens[];
310
extern _CONST double tens[];
311
 
312
 
313
double _EXFUN(_mprec_log10,(int));

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.