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

Subversion Repositories or1k

[/] [or1k/] [tags/] [tn_m001/] [newlib/] [newlib/] [libc/] [stdlib/] [mprec.h] - Blame information for rev 39

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