strtod, strtold: Use the locale's decimal point.
[gnulib.git] / m4 / ceill.m4
blob863c34450b31d731ae6bc47075e323583974f2d3
1 # ceill.m4 serial 18
2 dnl Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
7 AC_DEFUN([gl_FUNC_CEILL],
9   m4_divert_text([DEFAULTS], [gl_ceill_required=plain])
10   AC_REQUIRE([gl_MATH_H_DEFAULTS])
11   AC_REQUIRE([gl_LONG_DOUBLE_VS_DOUBLE])
12   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
14   dnl Persuade glibc <math.h> to declare ceill().
15   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
17   dnl Test whether ceill() is declared.
18   AC_CHECK_DECLS([ceill], , , [[#include <math.h>]])
19   if test "$ac_cv_have_decl_ceill" = yes; then
20     dnl Test whether ceill() can be used without libm.
21     gl_FUNC_CEILL_LIBS
22     if test "$CEILL_LIBM" = "?"; then
23       dnl Sun C 5.0 on Solaris declares ceill() and has it in the system-wide
24       dnl libm.so, but not in the libm.so that the compiler uses.
25       REPLACE_CEILL=1
26     fi
27     m4_ifdef([gl_FUNC_CEILL_IEEE], [
28       if test $gl_ceill_required = ieee && test $REPLACE_CEILL = 0; then
29         AC_CACHE_CHECK([whether ceill works according to ISO C 99 with IEC 60559],
30           [gl_cv_func_ceill_ieee],
31           [
32             save_LIBS="$LIBS"
33             LIBS="$LIBS $CEILL_LIBM"
34             AC_RUN_IFELSE(
35               [AC_LANG_SOURCE([[
36 #ifndef __NO_MATH_INLINES
37 # define __NO_MATH_INLINES 1 /* for glibc */
38 #endif
39 #include <math.h>
40 ]gl_LONG_DOUBLE_MINUS_ZERO_CODE[
41 ]gl_LONG_DOUBLE_SIGNBIT_CODE[
42 static long double dummy (long double f) { return 0; }
43 int main (int argc, char *argv[])
45   long double (* volatile my_ceill) (long double) = argc ? ceill : dummy;
46   /* Test whether ceill (-0.3L) is -0.0L.  */
47   if (signbitl (minus_zerol) && !signbitl (my_ceill (-0.3L)))
48     return 1;
49   return 0;
51               ]])],
52               [gl_cv_func_ceill_ieee=yes],
53               [gl_cv_func_ceill_ieee=no],
54               [case "$host_os" in
55                                 # Guess yes on glibc systems.
56                  *-gnu* | gnu*) gl_cv_func_ceill_ieee="guessing yes" ;;
57                                 # Guess yes on native Windows.
58                  mingw*)        gl_cv_func_ceill_ieee="guessing yes" ;;
59                                 # If we don't know, assume the worst.
60                  *)             gl_cv_func_ceill_ieee="guessing no" ;;
61                esac
62               ])
63             LIBS="$save_LIBS"
64           ])
65         case "$gl_cv_func_ceill_ieee" in
66           *yes) ;;
67           *) REPLACE_CEILL=1 ;;
68         esac
69       fi
70     ])
71   else
72     HAVE_DECL_CEILL=0
73   fi
74   dnl On OpenBSD5.6 the system's native ceill() is buggy:
75   dnl it returns '0' for small values. Test for this anomaly.
76   if test $REPLACE_CEILL = 0 ; then
77     AC_CACHE_CHECK([whether ceill() breaks with small values],
78         [gl_cv_func_ceill_buggy],
79         [
80           save_LIBS="$LIBS"
81           LIBS="$CEILL_LIBM"
82           AC_RUN_IFELSE(
83            [AC_LANG_PROGRAM(
84              [[#include <math.h>
85 long double d = 0.3L;]],
86              [[return (!(ceill (d) == 1)); ]])],
87              [gl_cv_func_ceill_buggy=no], [gl_cv_func_ceill_buggy=yes],
88              [case "$host_os" in
89                 openbsd*) gl_cv_func_ceill_buggy="guessing yes" ;;
90                           # Guess no on native Windows.
91                 mingw*)   gl_cv_func_ceill_buggy="guessing no" ;;
92                 *)        gl_cv_func_ceill_buggy="guessing no" ;;
93               esac
94              ])
95           LIBS="$save_LIBS"
96         ])
97     case "$gl_cv_func_ceill_buggy" in
98       *yes)
99         REPLACE_CEILL=1 ;;
100     esac
101   fi
102   if test $HAVE_DECL_CEILL = 0 || test $REPLACE_CEILL = 1; then
103     dnl Find libraries needed to link lib/ceill.c.
104     if test $HAVE_SAME_LONG_DOUBLE_AS_DOUBLE = 1; then
105       AC_REQUIRE([gl_FUNC_CEIL])
106       CEILL_LIBM="$CEIL_LIBM"
107     else
108       CEILL_LIBM=
109     fi
110   fi
111   AC_SUBST([CEILL_LIBM])
114 # Determines the libraries needed to get the ceill() function.
115 # Sets CEILL_LIBM.
116 AC_DEFUN([gl_FUNC_CEILL_LIBS],
118   gl_CACHE_VAL_SILENT([gl_cv_func_ceill_libm], [
119     gl_cv_func_ceill_libm=?
120     AC_LINK_IFELSE(
121       [AC_LANG_PROGRAM(
122          [[#ifndef __NO_MATH_INLINES
123            # define __NO_MATH_INLINES 1 /* for glibc */
124            #endif
125            #include <math.h>
126            long double (*funcptr) (long double) = ceill;
127            long double x;]],
128          [[x = funcptr(x) + ceill(x);]])],
129       [gl_cv_func_ceill_libm=])
130     if test "$gl_cv_func_ceill_libm" = "?"; then
131       save_LIBS="$LIBS"
132       LIBS="$LIBS -lm"
133       AC_LINK_IFELSE(
134         [AC_LANG_PROGRAM(
135            [[#ifndef __NO_MATH_INLINES
136              # define __NO_MATH_INLINES 1 /* for glibc */
137              #endif
138              #include <math.h>
139              long double (*funcptr) (long double) = ceill;
140              long double x;]],
141            [[x = funcptr(x) + ceill(x);]])],
142         [gl_cv_func_ceill_libm="-lm"])
143       LIBS="$save_LIBS"
144     fi
145   ])
146   CEILL_LIBM="$gl_cv_func_ceill_libm"