Rev 5222 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5222 | Rev 6324 | ||
---|---|---|---|
1 | /* flonum.h - Floating point package |
1 | /* flonum.h - Floating point package |
2 | Copyright 1987, 1990, 1991, 1992, 1994, 1996, 2000, 2003, 2005, 2007 |
- | |
3 | Free Software Foundation, Inc. |
2 | Copyright (C) 1987-2015 Free Software Foundation, Inc. |
4 | 3 | ||
5 | This file is part of GAS, the GNU Assembler. |
4 | This file is part of GAS, the GNU Assembler. |
6 | 5 | ||
7 | GAS is free software; you can redistribute it and/or modify |
6 | 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 |
7 | it under the terms of the GNU General Public License as published by |
9 | the Free Software Foundation; either version 3, or (at your option) |
8 | the Free Software Foundation; either version 3, or (at your option) |
10 | any later version. |
9 | any later version. |
11 | 10 | ||
12 | GAS is distributed in the hope that it will be useful, |
11 | GAS is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
14 | GNU General Public License for more details. |
16 | 15 | ||
17 | You should have received a copy of the GNU General Public License |
16 | You should have received a copy of the GNU General Public License |
18 | along with GAS; see the file COPYING. If not, write to the Free |
17 | along with GAS; see the file COPYING. If not, write to the Free |
19 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
18 | Software Foundation, 51 Franklin Street - Fifth Floor, Boston, MA |
20 | 02110-1301, USA. */ |
19 | 02110-1301, USA. */ |
21 | 20 | ||
22 | /***********************************************************************\ |
21 | /***********************************************************************\ |
23 | * * |
22 | * * |
24 | * Arbitrary-precision floating point arithmetic. * |
23 | * Arbitrary-precision floating point arithmetic. * |
25 | * * |
24 | * * |
26 | * * |
25 | * * |
27 | * Notation: a floating point number is expressed as * |
26 | * Notation: a floating point number is expressed as * |
28 | * MANTISSA * (2 ** EXPONENT). * |
27 | * MANTISSA * (2 ** EXPONENT). * |
29 | * * |
28 | * * |
30 | * If this offends more traditional mathematicians, then * |
29 | * If this offends more traditional mathematicians, then * |
31 | * please tell me your nomenclature for flonums! * |
30 | * please tell me your nomenclature for flonums! * |
32 | * * |
31 | * * |
33 | \***********************************************************************/ |
32 | \***********************************************************************/ |
34 | 33 | ||
35 | #include "bignum.h" |
34 | #include "bignum.h" |
36 | 35 | ||
37 | /***********************************************************************\ |
36 | /***********************************************************************\ |
38 | * * |
37 | * * |
39 | * Variable precision floating point numbers. * |
38 | * Variable precision floating point numbers. * |
40 | * * |
39 | * * |
41 | * Exponent is the place value of the low littlenum. E.g.: * |
40 | * Exponent is the place value of the low littlenum. E.g.: * |
42 | * If 0: low points to the units littlenum. * |
41 | * If 0: low points to the units littlenum. * |
43 | * If 1: low points to the LITTLENUM_RADIX littlenum. * |
42 | * If 1: low points to the LITTLENUM_RADIX littlenum. * |
44 | * If -1: low points to the 1/LITTLENUM_RADIX littlenum. * |
43 | * If -1: low points to the 1/LITTLENUM_RADIX littlenum. * |
45 | * * |
44 | * * |
46 | \***********************************************************************/ |
45 | \***********************************************************************/ |
47 | 46 | ||
48 | /* JF: A sign value of 0 means we have been asked to assemble NaN |
47 | /* JF: A sign value of 0 means we have been asked to assemble NaN |
49 | A sign value of 'P' means we've been asked to assemble +Inf |
48 | A sign value of 'P' means we've been asked to assemble +Inf |
50 | A sign value of 'N' means we've been asked to assemble -Inf |
49 | A sign value of 'N' means we've been asked to assemble -Inf |
51 | */ |
50 | */ |
52 | struct FLONUM_STRUCT { |
51 | struct FLONUM_STRUCT { |
53 | LITTLENUM_TYPE *low; /* low order littlenum of a bignum */ |
52 | LITTLENUM_TYPE *low; /* low order littlenum of a bignum */ |
54 | LITTLENUM_TYPE *high; /* high order littlenum of a bignum */ |
53 | LITTLENUM_TYPE *high; /* high order littlenum of a bignum */ |
55 | LITTLENUM_TYPE *leader; /* -> 1st non-zero littlenum */ |
54 | LITTLENUM_TYPE *leader; /* -> 1st non-zero littlenum */ |
56 | /* If flonum is 0.0, leader==low-1 */ |
55 | /* If flonum is 0.0, leader==low-1 */ |
57 | long exponent; /* base LITTLENUM_RADIX */ |
56 | long exponent; /* base LITTLENUM_RADIX */ |
58 | char sign; /* '+' or '-' */ |
57 | char sign; /* '+' or '-' */ |
59 | }; |
58 | }; |
60 | 59 | ||
61 | typedef struct FLONUM_STRUCT FLONUM_TYPE; |
60 | typedef struct FLONUM_STRUCT FLONUM_TYPE; |
62 | 61 | ||
63 | /***********************************************************************\ |
62 | /***********************************************************************\ |
64 | * * |
63 | * * |
65 | * Since we can (& do) meet with exponents like 10^5000, it * |
64 | * Since we can (& do) meet with exponents like 10^5000, it * |
66 | * is silly to make a table of ~ 10,000 entries, one for each * |
65 | * is silly to make a table of ~ 10,000 entries, one for each * |
67 | * power of 10. We keep a table where item [n] is a struct * |
66 | * power of 10. We keep a table where item [n] is a struct * |
68 | * FLONUM_FLOATING_POINT representing 10^(2^n). We then * |
67 | * FLONUM_FLOATING_POINT representing 10^(2^n). We then * |
69 | * multiply appropriate entries from this table to get any * |
68 | * multiply appropriate entries from this table to get any * |
70 | * particular power of 10. For the example of 10^5000, a table * |
69 | * particular power of 10. For the example of 10^5000, a table * |
71 | * of just 25 entries suffices: 10^(2^-12)...10^(2^+12). * |
70 | * of just 25 entries suffices: 10^(2^-12)...10^(2^+12). * |
72 | * * |
71 | * * |
73 | \***********************************************************************/ |
72 | \***********************************************************************/ |
74 | 73 | ||
75 | extern const FLONUM_TYPE flonum_positive_powers_of_ten[]; |
74 | extern const FLONUM_TYPE flonum_positive_powers_of_ten[]; |
76 | extern const FLONUM_TYPE flonum_negative_powers_of_ten[]; |
75 | extern const FLONUM_TYPE flonum_negative_powers_of_ten[]; |
77 | extern const int table_size_of_flonum_powers_of_ten; |
76 | extern const int table_size_of_flonum_powers_of_ten; |
78 | /* Flonum_XXX_powers_of_ten[] table has legal indices from 0 to |
77 | /* Flonum_XXX_powers_of_ten[] table has legal indices from 0 to |
79 | + this number inclusive. */ |
78 | + this number inclusive. */ |
80 | 79 | ||
81 | /***********************************************************************\ |
80 | /***********************************************************************\ |
82 | * * |
81 | * * |
83 | * Declare worker functions. * |
82 | * Declare worker functions. * |
84 | * * |
83 | * * |
85 | \***********************************************************************/ |
84 | \***********************************************************************/ |
86 | 85 | ||
87 | int atof_generic (char **address_of_string_pointer, |
86 | int atof_generic (char **address_of_string_pointer, |
88 | const char *string_of_decimal_marks, |
87 | const char *string_of_decimal_marks, |
89 | const char *string_of_decimal_exponent_marks, |
88 | const char *string_of_decimal_exponent_marks, |
90 | FLONUM_TYPE * address_of_generic_floating_point_number); |
89 | FLONUM_TYPE * address_of_generic_floating_point_number); |
91 | 90 | ||
92 | void flonum_copy (FLONUM_TYPE * in, FLONUM_TYPE * out); |
91 | void flonum_copy (FLONUM_TYPE * in, FLONUM_TYPE * out); |
93 | void flonum_multip (const FLONUM_TYPE * a, const FLONUM_TYPE * b, |
92 | void flonum_multip (const FLONUM_TYPE * a, const FLONUM_TYPE * b, |
94 | FLONUM_TYPE * product); |
93 | FLONUM_TYPE * product); |
95 | 94 | ||
96 | /***********************************************************************\ |
95 | /***********************************************************************\ |
97 | * * |
96 | * * |
98 | * Declare error codes. * |
97 | * Declare error codes. * |
99 | * * |
98 | * * |
100 | \***********************************************************************/ |
99 | \***********************************************************************/ |
101 | 100 | ||
102 | #define ERROR_EXPONENT_OVERFLOW (2) |
101 | #define ERROR_EXPONENT_OVERFLOW (2) |