1
/* Supplemental information about the floating-point formats.
2
Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
3
Written by Bruno Haible <bruno@clisp.org>, 2007.
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation; either version 2, or (at your option)
10
This program 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
13
GNU Lesser General Public License for more details.
15
You should have received a copy of the GNU Lesser General Public License
16
along with this program; if not, write to the Free Software Foundation,
17
Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
22
/* Number of bits in the mantissa of a floating-point number, including the
25
# define FLT_MANT_BIT FLT_MANT_DIG
26
# define DBL_MANT_BIT DBL_MANT_DIG
27
# define LDBL_MANT_BIT LDBL_MANT_DIG
29
# define FLT_MANT_BIT (FLT_MANT_DIG * 2)
30
# define DBL_MANT_BIT (DBL_MANT_DIG * 2)
31
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 2)
33
# define FLT_MANT_BIT (FLT_MANT_DIG * 4)
34
# define DBL_MANT_BIT (DBL_MANT_DIG * 4)
35
# define LDBL_MANT_BIT (LDBL_MANT_DIG * 4)
38
/* Bit mask that can be used to mask the exponent, as an unsigned number. */
39
#define FLT_EXP_MASK ((FLT_MAX_EXP - FLT_MIN_EXP) | 7)
40
#define DBL_EXP_MASK ((DBL_MAX_EXP - DBL_MIN_EXP) | 7)
41
#define LDBL_EXP_MASK ((LDBL_MAX_EXP - LDBL_MIN_EXP) | 7)
43
/* Number of bits used for the exponent of a floating-point number, including
44
the exponent's sign. */
46
(FLT_EXP_MASK < 0x100 ? 8 : \
47
FLT_EXP_MASK < 0x200 ? 9 : \
48
FLT_EXP_MASK < 0x400 ? 10 : \
49
FLT_EXP_MASK < 0x800 ? 11 : \
50
FLT_EXP_MASK < 0x1000 ? 12 : \
51
FLT_EXP_MASK < 0x2000 ? 13 : \
52
FLT_EXP_MASK < 0x4000 ? 14 : \
53
FLT_EXP_MASK < 0x8000 ? 15 : \
54
FLT_EXP_MASK < 0x10000 ? 16 : \
55
FLT_EXP_MASK < 0x20000 ? 17 : \
56
FLT_EXP_MASK < 0x40000 ? 18 : \
57
FLT_EXP_MASK < 0x80000 ? 19 : \
58
FLT_EXP_MASK < 0x100000 ? 20 : \
59
FLT_EXP_MASK < 0x200000 ? 21 : \
60
FLT_EXP_MASK < 0x400000 ? 22 : \
61
FLT_EXP_MASK < 0x800000 ? 23 : \
62
FLT_EXP_MASK < 0x1000000 ? 24 : \
63
FLT_EXP_MASK < 0x2000000 ? 25 : \
64
FLT_EXP_MASK < 0x4000000 ? 26 : \
65
FLT_EXP_MASK < 0x8000000 ? 27 : \
66
FLT_EXP_MASK < 0x10000000 ? 28 : \
67
FLT_EXP_MASK < 0x20000000 ? 29 : \
68
FLT_EXP_MASK < 0x40000000 ? 30 : \
69
FLT_EXP_MASK <= 0x7fffffff ? 31 : \
72
(DBL_EXP_MASK < 0x100 ? 8 : \
73
DBL_EXP_MASK < 0x200 ? 9 : \
74
DBL_EXP_MASK < 0x400 ? 10 : \
75
DBL_EXP_MASK < 0x800 ? 11 : \
76
DBL_EXP_MASK < 0x1000 ? 12 : \
77
DBL_EXP_MASK < 0x2000 ? 13 : \
78
DBL_EXP_MASK < 0x4000 ? 14 : \
79
DBL_EXP_MASK < 0x8000 ? 15 : \
80
DBL_EXP_MASK < 0x10000 ? 16 : \
81
DBL_EXP_MASK < 0x20000 ? 17 : \
82
DBL_EXP_MASK < 0x40000 ? 18 : \
83
DBL_EXP_MASK < 0x80000 ? 19 : \
84
DBL_EXP_MASK < 0x100000 ? 20 : \
85
DBL_EXP_MASK < 0x200000 ? 21 : \
86
DBL_EXP_MASK < 0x400000 ? 22 : \
87
DBL_EXP_MASK < 0x800000 ? 23 : \
88
DBL_EXP_MASK < 0x1000000 ? 24 : \
89
DBL_EXP_MASK < 0x2000000 ? 25 : \
90
DBL_EXP_MASK < 0x4000000 ? 26 : \
91
DBL_EXP_MASK < 0x8000000 ? 27 : \
92
DBL_EXP_MASK < 0x10000000 ? 28 : \
93
DBL_EXP_MASK < 0x20000000 ? 29 : \
94
DBL_EXP_MASK < 0x40000000 ? 30 : \
95
DBL_EXP_MASK <= 0x7fffffff ? 31 : \
97
#define LDBL_EXP_BIT \
98
(LDBL_EXP_MASK < 0x100 ? 8 : \
99
LDBL_EXP_MASK < 0x200 ? 9 : \
100
LDBL_EXP_MASK < 0x400 ? 10 : \
101
LDBL_EXP_MASK < 0x800 ? 11 : \
102
LDBL_EXP_MASK < 0x1000 ? 12 : \
103
LDBL_EXP_MASK < 0x2000 ? 13 : \
104
LDBL_EXP_MASK < 0x4000 ? 14 : \
105
LDBL_EXP_MASK < 0x8000 ? 15 : \
106
LDBL_EXP_MASK < 0x10000 ? 16 : \
107
LDBL_EXP_MASK < 0x20000 ? 17 : \
108
LDBL_EXP_MASK < 0x40000 ? 18 : \
109
LDBL_EXP_MASK < 0x80000 ? 19 : \
110
LDBL_EXP_MASK < 0x100000 ? 20 : \
111
LDBL_EXP_MASK < 0x200000 ? 21 : \
112
LDBL_EXP_MASK < 0x400000 ? 22 : \
113
LDBL_EXP_MASK < 0x800000 ? 23 : \
114
LDBL_EXP_MASK < 0x1000000 ? 24 : \
115
LDBL_EXP_MASK < 0x2000000 ? 25 : \
116
LDBL_EXP_MASK < 0x4000000 ? 26 : \
117
LDBL_EXP_MASK < 0x8000000 ? 27 : \
118
LDBL_EXP_MASK < 0x10000000 ? 28 : \
119
LDBL_EXP_MASK < 0x20000000 ? 29 : \
120
LDBL_EXP_MASK < 0x40000000 ? 30 : \
121
LDBL_EXP_MASK <= 0x7fffffff ? 31 : \
124
/* Number of bits used for a floating-point number: the mantissa (not
125
counting the "hidden bit", since it may or may not be explicit), the
126
exponent, and the sign. */
127
#define FLT_TOTAL_BIT ((FLT_MANT_BIT - 1) + FLT_EXP_BIT + 1)
128
#define DBL_TOTAL_BIT ((DBL_MANT_BIT - 1) + DBL_EXP_BIT + 1)
129
#define LDBL_TOTAL_BIT ((LDBL_MANT_BIT - 1) + LDBL_EXP_BIT + 1)
131
/* Number of bytes used for a floating-point number.
132
This can be smaller than the 'sizeof'. For example, on i386 systems,
133
'long double' most often have LDBL_MANT_BIT = 64, LDBL_EXP_BIT = 16, hence
134
LDBL_TOTAL_BIT = 80 bits, i.e. 10 bytes of consecutive memory, but
135
sizeof (long double) = 12 or = 16. */
136
#define SIZEOF_FLT ((FLT_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
137
#define SIZEOF_DBL ((DBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
138
#define SIZEOF_LDBL ((LDBL_TOTAL_BIT + CHAR_BIT - 1) / CHAR_BIT)
140
/* Verify that SIZEOF_FLT <= sizeof (float) etc. */
141
typedef int verify_sizeof_flt[2 * (SIZEOF_FLT <= sizeof (float)) - 1];
142
typedef int verify_sizeof_dbl[2 * (SIZEOF_DBL <= sizeof (double)) - 1];
143
typedef int verify_sizeof_ldbl[2 * (SIZEOF_LDBL <= sizeof (long double)) - 1];