]>
Commit | Line | Data |
---|---|---|
28f540f4 | 1 | /* Header file for constants used in floating point <-> decimal conversions. |
581c785b | 2 | Copyright (C) 1995-2022 Free Software Foundation, Inc. |
7cc27f44 | 3 | This file is part of the GNU C Library. |
28f540f4 | 4 | |
7cc27f44 | 5 | The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
6 | modify it under the terms of the GNU Lesser General Public |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
28f540f4 | 9 | |
7cc27f44 UD |
10 | The GNU C Library is distributed in the hope that it will be useful, |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
41bdb6e2 | 13 | Lesser General Public License for more details. |
28f540f4 | 14 | |
41bdb6e2 | 15 | You should have received a copy of the GNU Lesser General Public |
59ba27a6 | 16 | License along with the GNU C Library; if not, see |
5a82c748 | 17 | <https://www.gnu.org/licenses/>. */ |
28f540f4 RM |
18 | |
19 | #ifndef _FPIOCONST_H | |
20 | #define _FPIOCONST_H | |
21 | ||
22 | #include <float.h> | |
76235ed4 | 23 | #include <math.h> |
264befa8 | 24 | #include <gmp.h> |
28f540f4 RM |
25 | |
26 | ||
27 | /* These values are used by __printf_fp, where they are noncritical (if the | |
28 | value is not large enough, it will just be slower); and by | |
29 | strtof/strtod/strtold, where it is critical (it's used for overflow | |
30 | detection). | |
31 | ||
32 | XXX These should be defined in <float.h>. For the time being, we have the | |
33 | IEEE754 values here. */ | |
34 | ||
5ce98c3f | 35 | #if !defined __NO_LONG_DOUBLE_MATH && __LDBL_MAX_EXP__ > 1024 |
390955cb UD |
36 | # define LDBL_MAX_10_EXP_LOG 12 /* = floor(log_2(LDBL_MAX_10_EXP)) */ |
37 | #else | |
38 | # define LDBL_MAX_10_EXP_LOG 8 /* = floor(log_2(LDBL_MAX_10_EXP)) */ | |
39 | #endif | |
28f540f4 RM |
40 | #define DBL_MAX_10_EXP_LOG 8 /* = floor(log_2(DBL_MAX_10_EXP)) */ |
41 | #define FLT_MAX_10_EXP_LOG 5 /* = floor(log_2(FLT_MAX_10_EXP)) */ | |
42 | ||
82c19bdf PM |
43 | /* On some machines, _Float128 may be ABI-distinct from long double (e.g |
44 | IBM extended precision). */ | |
45 | #include <bits/floatn.h> | |
46 | ||
cf2046ec GG |
47 | #if __HAVE_DISTINCT_FLOAT128 |
48 | # define FLT128_MAX_10_EXP_LOG 12 /* = floor(log_2(FLT128_MAX_10_EXP)) */ | |
49 | #endif | |
50 | ||
af92131a | 51 | /* For strtold, we need powers of 10 up to floor (log_2 (LDBL_MANT_DIG |
82c19bdf PM |
52 | - LDBL_MIN_EXP + 2)). When _Float128 is enabled in libm and it is |
53 | ABI-distinct from long double (e.g. on powerpc64le), we also need powers | |
54 | of 10 up to floor (log_2 (FLT128_MANT_DIG - FLT128_MIN_EXP + 2)). */ | |
55 | #define FPIOCONST_HAVE_EXTENDED_RANGE \ | |
56 | ((!defined __NO_LONG_DOUBLE_MATH && __LDBL_MAX_EXP__ > 1024) \ | |
57 | || __HAVE_DISTINCT_FLOAT128) | |
58 | ||
59 | #if FPIOCONST_HAVE_EXTENDED_RANGE | |
af92131a JM |
60 | # define FPIOCONST_POW10_ARRAY_SIZE 15 |
61 | #else | |
62 | # define FPIOCONST_POW10_ARRAY_SIZE 11 | |
63 | #endif | |
28f540f4 | 64 | |
c4563d2d | 65 | /* The array with the number representation. */ |
418f1701 | 66 | extern const mp_limb_t __tens[] attribute_hidden; |
c4563d2d | 67 | |
28f540f4 RM |
68 | /* Table of powers of ten. This is used by __printf_fp and by |
69 | strtof/strtod/strtold. */ | |
70 | struct mp_power | |
71 | { | |
c4563d2d | 72 | size_t arrayoff; /* Offset in `__tens'. */ |
28f540f4 RM |
73 | mp_size_t arraysize; /* Size of the array. */ |
74 | int p_expo; /* Exponent of the number 10^(2^i). */ | |
75 | int m_expo; /* Exponent of the number 10^-(2^i-1). */ | |
76 | }; | |
af92131a | 77 | extern const struct mp_power _fpioconst_pow10[FPIOCONST_POW10_ARRAY_SIZE] |
418f1701 | 78 | attribute_hidden; |
28f540f4 | 79 | |
bfc04a9f RM |
80 | /* The constants in the array `_fpioconst_pow10' have an offset. */ |
81 | #if BITS_PER_MP_LIMB == 32 | |
82 | # define _FPIO_CONST_OFFSET 2 | |
83 | #else | |
84 | # define _FPIO_CONST_OFFSET 1 | |
85 | #endif | |
86 | ||
28f540f4 RM |
87 | |
88 | #endif /* fpioconst.h */ |