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