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