summaryrefslogtreecommitdiffstats
path: root/gl/float.c
diff options
context:
space:
mode:
Diffstat (limited to 'gl/float.c')
-rw-r--r--gl/float.c98
1 files changed, 91 insertions, 7 deletions
diff --git a/gl/float.c b/gl/float.c
index a9ea40b0..2e95957a 100644
--- a/gl/float.c
+++ b/gl/float.c
@@ -1,5 +1,5 @@
1/* Auxiliary definitions for <float.h>. 1/* Auxiliary definitions for <float.h>.
2 Copyright (C) 2011-2024 Free Software Foundation, Inc. 2 Copyright (C) 2011-2026 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2011. 3 Written by Bruno Haible <bruno@clisp.org>, 2011.
4 4
5 This file is free software: you can redistribute it and/or modify 5 This file is free software: you can redistribute it and/or modify
@@ -20,14 +20,98 @@
20/* Specification. */ 20/* Specification. */
21#include <float.h> 21#include <float.h>
22 22
23#if (defined _ARCH_PPC || defined _POWER) && (defined _AIX || defined __linux__) && (LDBL_MANT_DIG == 106) && defined __GNUC__ 23#if GNULIB_defined_long_double_union
24const union gl_long_double_union gl_LDBL_MAX = 24# ifdef __i386__
25 { { DBL_MAX, DBL_MAX / (double)134217728UL / (double)134217728UL } };
26#elif defined __i386__
27const union gl_long_double_union gl_LDBL_MAX = 25const union gl_long_double_union gl_LDBL_MAX =
28 { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } }; 26 { { 0xFFFFFFFF, 0xFFFFFFFF, 32766 } };
29#else 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>. */
34const 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. */
42gl_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. */
58gl_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. */
79gl_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
30/* This declaration is solely to ensure that after preprocessing 115/* This declaration is solely to ensure that after preprocessing
31 this file is never empty. */ 116 this file is never empty. */
32typedef int dummy; 117typedef int dummy;
33#endif