Debian Codegraph @

m4/float_h.m4

raw
1 # float_h.m4
2 # serial 15
3 dnl Copyright (C) 2007, 2009-2024 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* | irix*)
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 float maxf = FLT_NORM_MAX;
67 double maxd = DBL_NORM_MAX;
68 long double maxl = LDBL_NORM_MAX;
69 ]],
70 [[float sf = FLT_SNAN;
71 double sd = DBL_SNAN;
72 long double sl = LDBL_SNAN;
73 return (sf != 0) + (sd != 0) + (sl != 0);
74 ]])],
75 [gl_cv_header_float_h_isoc23=yes],
76 [gl_cv_header_float_h_isoc23=no])
77 ])
78 if test $gl_cv_header_float_h_isoc23 != yes; then
79 GL_GENERATE_FLOAT_H=true
80 REPLACE_FLOAT_SNAN=1
81 fi
82
83 dnl Test against glibc-2.7 Linux/SPARC64 bug.
84 REPLACE_ITOLD=0
85 AC_CACHE_CHECK([whether conversion from 'int' to 'long double' works],
86 [gl_cv_func_itold_works],
87 [
88 AC_RUN_IFELSE(
89 [AC_LANG_SOURCE([[
90 int i = -1;
91 volatile long double ld;
92 int main ()
93 {
94 ld += i * 1.0L;
95 if (ld > 0)
96 return 1;
97 return 0;
98 }]])],
99 [gl_cv_func_itold_works=yes],
100 [gl_cv_func_itold_works=no],
101 [case "$host" in
102 sparc*-*-linux*)
103 AC_COMPILE_IFELSE(
104 [AC_LANG_SOURCE(
105 [[#if defined __LP64__ || defined __arch64__
106 int ok;
107 #else
108 error fail
109 #endif
110 ]])],
111 [gl_cv_func_itold_works="guessing no"],
112 [gl_cv_func_itold_works="guessing yes"])
113 ;;
114 # Guess yes on native Windows.
115 mingw* | windows*)
116 gl_cv_func_itold_works="guessing yes" ;;
117 *)
118 gl_cv_func_itold_works="guessing yes" ;;
119 esac
120 ])
121 ])
122 case "$gl_cv_func_itold_works" in
123 *no)
124 REPLACE_ITOLD=1
125 dnl We add the workaround to <float.h> but also to <math.h>,
126 dnl to increase the chances that the fix function gets pulled in.
127 GL_GENERATE_FLOAT_H=true
128 ;;
129 esac
130
131 if $GL_GENERATE_FLOAT_H; then
132 gl_NEXT_HEADERS([float.h])
133 fi
134 AC_SUBST([REPLACE_ITOLD])
135 ])