annotate lib/float+.h @ 273:88bbffa404ea 2.5 2.5

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