Debian Codegraph @

lib/float.c

raw
1 /* Auxiliary definitions for <float.h>.
2 Copyright (C) 2011-2026 Free Software Foundation, Inc.
3 Written by Bruno Haible <[email protected]>, 2011.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file 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.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 #include <config.h>
19
20 /* Specification. */
21 #include <float.h>
22
23 #if GNULIB_defined_long_double_union
24 # ifdef __i386__
25 const union gl_long_double_union gl_LDBL_MAX =
26 { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
27 # endif
28 # if defined __i386__ && (defined __FreeBSD__ || defined __DragonFly__)
29 /* We can't even simply evaluate the formula (LDBL_MIN / 9223372036854775808.0L)
30 at run time, because it would require BEGIN_LONG_DOUBLE_ROUNDING /
31 END_LONG_DOUBLE_ROUNDING invocations. It simpler to just write down the
32 representation of LDBL_TRUE_MIN, based on
33 <https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format>. */
34 const union gl_long_double_union gl_LDBL_TRUE_MIN =
35 { { 0x00000001, 0x00000000, 0 } };
36 # endif
37 #endif
38
39 #if GNULIB_defined_FLT_SNAN
40 /* Define like memory_positive_SNaNf(), see signed-snan.h and snan.h,
41 or like setpayloadsigf() with an arbitrary payload. */
42 gl_FLT_SNAN_t gl_FLT_SNAN =
43 # if FLT_MANT_DIG == 24
44 # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
45 /* sign bit: 0, 8 exponent bits: all 1, next bit: 1, payload: 0b10...0 */
46 { { 0x7FE00000U } }
47 # else
48 /* sign bit: 0, 8 exponent bits: all 1, next bit: 0, payload: 0b10...0 */
49 { { 0x7FA00000U } }
50 # endif
51 # endif
52 ;
53 #endif
54
55 #if GNULIB_defined_DBL_SNAN
56 /* Define like memory_positive_SNaNd(), see signed-snan.h and snan.h,
57 or like setpayloadsig() with an arbitrary payload. */
58 gl_DBL_SNAN_t gl_DBL_SNAN =
59 # if DBL_MANT_DIG == 53
60 # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
61 /* sign bit: 0, 11 exponent bits: all 1, next bit: 1, payload: 0b10...0 */
62 { { 0x7FFC000000000000ULL } }
63 # else
64 /* sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0 */
65 { { 0x7FF4000000000000ULL } }
66 # endif
67 # endif
68 ;
69 #endif
70
71 #if GNULIB_defined_LDBL_SNAN
72 # ifdef WORDS_BIGENDIAN
73 # define TWO(hi,lo) { hi, lo }
74 # else
75 # define TWO(hi,lo) { lo, hi }
76 # endif
77 /* Define like memory_positive_SNaNl(), see signed-snan.h and snan.h,
78 or like setpayloadsigl() with an arbitrary payload. */
79 gl_LDBL_SNAN_t gl_LDBL_SNAN =
80 # if LDBL_MANT_DIG == 53 /* on arm, hppa, mips, sh, but also MSVC */
81 # if defined __hppa || (defined __mips__ && !MIPS_NAN2008_FLOAT) || defined __sh__
82 /* sign bit: 0, 11 exponent bits: all 1, next bit: 1, payload: 0b10...0 */
83 { { 0x7FFC000000000000ULL } }
84 # else
85 /* sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0 */
86 { { 0x7FF4000000000000ULL } }
87 # endif
88 # elif LDBL_MANT_DIG == 64 /* on i386, x86_64, ia64, m68k */
89 # if defined __m68k__
90 /* sign bit: 0, 15 exponent bits: all 1, 16 gap bits: all 0,
91 always=1 bit: 1, next bit: 0, payload: 0b10...0 */
92 { { 0x7FFF0000ULL, 0xA0000000ULL, 0x00000000ULL } }
93 # else
94 /* sign bit: 0, 15 exponent bits: all 1, always=1 bit: 1, next bit: 0, payload: 0b10...0
95 (see <https://en.wikipedia.org/wiki/Extended_precision#x86_extended_precision_format>) */
96 { TWO (0x00007FFFULL, 0xA000000000000000ULL) }
97 # endif
98 # elif LDBL_MANT_DIG == 106 /* on powerpc, powerpc64, powerpc64le */
99 /* most-significant double:
100 sign bit: 0, 11 exponent bits: all 1, next bit: 0, payload: 0b10...0,
101 least-significant double: 0.0 */
102 { { 0x7FF4000000000000ULL, 0ULL } }
103 # elif LDBL_MANT_DIG == 113 /* on alpha, arm64, loongarch64, mips64, riscv64, s390x, sparc64 */
104 # if (defined __mips__ && !MIPS_NAN2008_FLOAT)
105 /* sign bit: 0, 15 exponent bits: all 1, next bit: 1, payload: 0b10...0 */
106 { TWO (0x7FFFC00000000000ULL, 0ULL) }
107 # else
108 /* sign bit: 0, 15 exponent bits: all 1, next bit: 0, payload: 0b10...0 */
109 { TWO (0x7FFF400000000000ULL, 0ULL) }
110 # endif
111 # endif
112 ;
113 #endif
114
115 /* This declaration is solely to ensure that after preprocessing
116 this file is never empty. */
117 typedef int dummy;