Commit | Line | Data |
---|---|---|
fecd2382 | 1 | /* flonum.h - Floating point package |
6efd877d KR |
2 | |
3 | Copyright (C) 1987, 1990, 1991, 1992 Free Software Foundation, Inc. | |
4 | ||
a39116f1 | 5 | This file is part of GAS, the GNU Assembler. |
6efd877d | 6 | |
a39116f1 RP |
7 | GAS is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by | |
9 | the Free Software Foundation; either version 2, or (at your option) | |
10 | any later version. | |
6efd877d | 11 | |
a39116f1 RP |
12 | GAS 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 General Public License for more details. | |
6efd877d | 16 | |
a39116f1 RP |
17 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to | |
19 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
fecd2382 | 20 | |
fecd2382 | 21 | /***********************************************************************\ |
a39116f1 RP |
22 | * * |
23 | * Arbitrary-precision floating point arithmetic. * | |
24 | * * | |
25 | * * | |
26 | * Notation: a floating point number is expressed as * | |
27 | * MANTISSA * (2 ** EXPONENT). * | |
28 | * * | |
29 | * If this offends more traditional mathematicians, then * | |
30 | * please tell me your nomenclature for flonums! * | |
31 | * * | |
32 | \***********************************************************************/ | |
6efd877d KR |
33 | #if (__STDC__ != 1) && !defined(const) |
34 | #define const /* empty */ | |
fecd2382 RP |
35 | #endif |
36 | ||
37 | #include "bignum.h" | |
38 | ||
39 | /***********************************************************************\ | |
a39116f1 RP |
40 | * * |
41 | * Variable precision floating point numbers. * | |
42 | * * | |
43 | * Exponent is the place value of the low littlenum. E.g.: * | |
44 | * If 0: low points to the units littlenum. * | |
45 | * If 1: low points to the LITTLENUM_RADIX littlenum. * | |
46 | * If -1: low points to the 1/LITTLENUM_RADIX littlenum. * | |
47 | * * | |
48 | \***********************************************************************/ | |
fecd2382 RP |
49 | |
50 | /* JF: A sign value of 0 means we have been asked to assemble NaN | |
51 | A sign value of 'P' means we've been asked to assemble +Inf | |
52 | A sign value of 'N' means we've been asked to assemble -Inf | |
a39116f1 | 53 | */ |
fecd2382 RP |
54 | struct FLONUM_STRUCT |
55 | { | |
6efd877d KR |
56 | LITTLENUM_TYPE *low; /* low order littlenum of a bignum */ |
57 | LITTLENUM_TYPE *high; /* high order littlenum of a bignum */ | |
58 | LITTLENUM_TYPE *leader; /* -> 1st non-zero littlenum */ | |
59 | /* If flonum is 0.0, leader==low-1 */ | |
60 | long exponent; /* base LITTLENUM_RADIX */ | |
61 | char sign; /* '+' or '-' */ | |
fecd2382 RP |
62 | }; |
63 | ||
64 | typedef struct FLONUM_STRUCT FLONUM_TYPE; | |
65 | ||
66 | ||
67 | /***********************************************************************\ | |
a39116f1 RP |
68 | * * |
69 | * Since we can (& do) meet with exponents like 10^5000, it * | |
70 | * is silly to make a table of ~ 10,000 entries, one for each * | |
71 | * power of 10. We keep a table where item [n] is a struct * | |
72 | * FLONUM_FLOATING_POINT representing 10^(2^n). We then * | |
73 | * multiply appropriate entries from this table to get any * | |
74 | * particular power of 10. For the example of 10^5000, a table * | |
75 | * of just 25 entries suffices: 10^(2^-12)...10^(2^+12). * | |
76 | * * | |
77 | \***********************************************************************/ | |
fecd2382 RP |
78 | |
79 | ||
80 | extern const FLONUM_TYPE flonum_positive_powers_of_ten[]; | |
81 | extern const FLONUM_TYPE flonum_negative_powers_of_ten[]; | |
82 | extern const int table_size_of_flonum_powers_of_ten; | |
a39116f1 RP |
83 | /* Flonum_XXX_powers_of_ten[] table has */ |
84 | /* legal indices from 0 to */ | |
85 | /* + this number inclusive. */ | |
fecd2382 RP |
86 | |
87 | ||
88 | ||
89 | /***********************************************************************\ | |
a39116f1 RP |
90 | * * |
91 | * Declare worker functions. * | |
92 | * * | |
93 | \***********************************************************************/ | |
fecd2382 | 94 | |
6efd877d | 95 | #if __STDC__ == 1 |
fecd2382 | 96 | |
6efd877d KR |
97 | int atof_generic (char **address_of_string_pointer, |
98 | const char *string_of_decimal_marks, | |
99 | const char *string_of_decimal_exponent_marks, | |
100 | FLONUM_TYPE * address_of_generic_floating_point_number); | |
fecd2382 | 101 | |
6efd877d KR |
102 | void flonum_copy (FLONUM_TYPE * in, FLONUM_TYPE * out); |
103 | void flonum_multip (const FLONUM_TYPE * a, const FLONUM_TYPE * b, FLONUM_TYPE * product); | |
fecd2382 | 104 | |
6efd877d | 105 | #else /* not __STDC__ */ |
fecd2382 | 106 | |
6efd877d KR |
107 | int atof_generic (); |
108 | void flonum_copy (); | |
109 | void flonum_multip (); | |
fecd2382 | 110 | |
6efd877d | 111 | #endif /* not __STDC__ */ |
fecd2382 RP |
112 | |
113 | /***********************************************************************\ | |
a39116f1 RP |
114 | * * |
115 | * Declare error codes. * | |
116 | * * | |
117 | \***********************************************************************/ | |
fecd2382 RP |
118 | |
119 | #define ERROR_EXPONENT_OVERFLOW (2) | |
120 | ||
8b228fe9 | 121 | /* end of flonum.h */ |