1 /* PSPP - a program for statistical analysis.
2 Copyright (C) 2023 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 #ifndef LIBPSPP_FLOAT_RANGE_H
18 #define LIBPSPP_FLOAT_RANGE_H 1
24 #error /* Defined in C2x <limits.h> */
27 /* Maximum positive integer 'double' represented with no loss of precision
28 (that is, with unit precision).
30 The maximum negative integer with this property is -DBL_UNIT_MAX. */
31 #if DBL_MANT_DIG == 53 /* 64-bit double */
32 #define DBL_UNIT_MAX 9007199254740992.0
33 #elif DBL_MANT_DIG == 64 /* 80-bit double */
34 #define DBL_UNIT_MAX 18446744073709551616.0
35 #elif DBL_MANT_DIG == 113 /* 128-bit double */
36 #define DBL_UNIT_MAX 10384593717069655257060992658440192.0
38 #error "Please define DBL_UNIT_MAX for your system (as 2**DBL_MANT_DIG)."
41 /* Intersection of ranges [LONG_MIN,LONG_MAX] and [-DBL_UNIT_MAX,DBL_UNIT_MAX],
42 as a range of 'long's. This range is the (largest contiguous) set of
43 integer values that can be safely converted between 'long' and 'double'
44 without loss of precision. */
45 #if DBL_MANT_DIG < LONG_WIDTH - 1
46 #define DBL_UNIT_LONG_MIN ((long) -DBL_UNIT_MAX)
47 #define DBL_UNIT_LONG_MAX ((long) DBL_UNIT_MAX)
49 #define DBL_UNIT_LONG_MIN LONG_MIN
50 #define DBL_UNIT_LONG_MAX LONG_MAX
53 #endif /* float-range.h */