Debian Codegraph @

m4/float_h.m4

raw
1 # float_h.m4
2 # serial 17
3 dnl Copyright (C) 2007, 2009-2026 Free Software Foundation, Inc.
4 dnl This file is free software; the Free Software Foundation
5 dnl gives unlimited permission to copy and/or distribute it,
6 dnl with or without modifications, as long as this notice is preserved.
7 dnl This file is offered as-is, without any warranty.
8
9 AC_DEFUN([gl_FLOAT_H],
10 [
11 AC_REQUIRE([AC_PROG_CC])
12 AC_REQUIRE([AC_CANONICAL_HOST])
13 GL_GENERATE_FLOAT_H=false
14 REPLACE_FLOAT_LDBL=0
15 case "$host_os" in
16 aix* | beos* | openbsd* | mirbsd*)
17 GL_GENERATE_FLOAT_H=true
18 ;;
19 freebsd* | dragonfly*)
20 case "$host_cpu" in
21 changequote(,)dnl
22 i[34567]86 )
23 changequote([,])dnl
24 GL_GENERATE_FLOAT_H=true
25 ;;
26 x86_64 )
27 # On x86_64 systems, the C compiler may still be generating
28 # 32-bit code.
29 AC_COMPILE_IFELSE(
30 [AC_LANG_SOURCE(
31 [[#if defined __LP64__ || defined __x86_64__ || defined __amd64__
32 int ok;
33 #else
34 error fail
35 #endif
36 ]])],
37 [],
38 [GL_GENERATE_FLOAT_H=true])
39 ;;
40 esac
41 ;;
42 linux*)
43 case "$host_cpu" in
44 powerpc*)
45 GL_GENERATE_FLOAT_H=true
46 ;;
47 esac
48 ;;
49 esac
50 case "$host_os" in
51 aix* | freebsd* | dragonfly* | linux*)
52 if $GL_GENERATE_FLOAT_H; then
53 REPLACE_FLOAT_LDBL=1
54 fi
55 ;;
56 esac
57
58 dnl Test for completeness w.r.t. ISO C 23.
59 REPLACE_FLOAT_SNAN=0
60 AC_CACHE_CHECK([whether float.h conforms to ISO C23],
61 [gl_cv_header_float_h_isoc23],
62 [AC_COMPILE_IFELSE(
63 [AC_LANG_PROGRAM(
64 [[#include <float.h>
65 int x[] = { FLT_DECIMAL_DIG, DBL_DECIMAL_DIG, LDBL_DECIMAL_DIG };
66 int y[] = { FLT_IS_IEC_60559, DBL_IS_IEC_60559, LDBL_IS_IEC_60559 };
67 float maxf = FLT_NORM_MAX;
68 double maxd = DBL_NORM_MAX;
69 long double maxl = LDBL_NORM_MAX;
70 ]],
71 [[float sf = FLT_SNAN;
72 double sd = DBL_SNAN;
73 long double sl = LDBL_SNAN;
74 return (sf != 0) + (sd != 0) + (sl != 0);
75 ]])],
76 [gl_cv_header_float_h_isoc23=yes],
77 [gl_cv_header_float_h_isoc23=no])
78 ])
79 if test $gl_cv_header_float_h_isoc23 != yes; then
80 GL_GENERATE_FLOAT_H=true
81 REPLACE_FLOAT_SNAN=1
82 fi
83
84 dnl Test against glibc-2.7 Linux/SPARC64 bug.
85 REPLACE_ITOLD=0
86 AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works],
87 [gl_cv_func_itold_works],
88 [
89 AC_RUN_IFELSE(
90 [AC_LANG_SOURCE([[
91 int i = -1;
92 volatile long double ld;
93 int main ()
94 {
95 ld += i * 1.0L;
96 if (ld > 0)
97 return 1;
98 return 0;
99 }]])],
100 [gl_cv_func_itold_works=yes],
101 [gl_cv_func_itold_works=no],
102 [case "$host" in
103 sparc*-*-linux*)
104 AC_COMPILE_IFELSE(
105 [AC_LANG_SOURCE(
106 [[#if defined __LP64__ || defined __arch64__
107 int ok;
108 #else
109 error fail
110 #endif
111 ]])],
112 [gl_cv_func_itold_works="guessing no"],
113 [gl_cv_func_itold_works="guessing yes"])
114 ;;
115 # Guess yes on native Windows.
116 mingw* | windows*)
117 gl_cv_func_itold_works="guessing yes" ;;
118 *)
119 gl_cv_func_itold_works="guessing yes" ;;
120 esac
121 ])
122 ])
123 case "$gl_cv_func_itold_works" in
124 *no)
125 REPLACE_ITOLD=1
126 dnl We add the workaround to <float.h> but also to <math.h>,
127 dnl to increase the chances that the fix function gets pulled in.
128 GL_GENERATE_FLOAT_H=true
129 ;;
130 esac
131
132 if $GL_GENERATE_FLOAT_H; then
133 gl_NEXT_HEADERS([float.h])
134 fi
135 AC_SUBST([REPLACE_ITOLD])
136 ])