| 1 | # ceil.m4 serial 9 |
| 2 | dnl Copyright (C) 2007, 2009-2013 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. |
| 6 | |
| 7 | AC_DEFUN([gl_FUNC_CEIL], |
| 8 | [ |
| 9 | m4_divert_text([DEFAULTS], [gl_ceil_required=plain]) |
| 10 | AC_REQUIRE([gl_MATH_H_DEFAULTS]) |
| 11 | dnl Test whether ceil() can be used without libm. |
| 12 | gl_FUNC_CEIL_LIBS |
| 13 | if test "$CEIL_LIBM" = "?"; then |
| 14 | CEIL_LIBM= |
| 15 | fi |
| 16 | m4_ifdef([gl_FUNC_CEIL_IEEE], [ |
| 17 | if test $gl_ceil_required = ieee && test $REPLACE_CEIL = 0; then |
| 18 | AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 19 | AC_CACHE_CHECK([whether ceil works according to ISO C 99 with IEC 60559], |
| 20 | [gl_cv_func_ceil_ieee], |
| 21 | [ |
| 22 | save_LIBS="$LIBS" |
| 23 | LIBS="$LIBS $CEIL_LIBM" |
| 24 | AC_RUN_IFELSE( |
| 25 | [AC_LANG_SOURCE([[ |
| 26 | #ifndef __NO_MATH_INLINES |
| 27 | # define __NO_MATH_INLINES 1 /* for glibc */ |
| 28 | #endif |
| 29 | #include <math.h> |
| 30 | ]gl_DOUBLE_MINUS_ZERO_CODE[ |
| 31 | ]gl_DOUBLE_SIGNBIT_CODE[ |
| 32 | static double dummy (double f) { return 0; } |
| 33 | int main (int argc, char *argv[]) |
| 34 | { |
| 35 | double (*my_ceil) (double) = argc ? ceil : dummy; |
| 36 | int result = 0; |
| 37 | /* Test whether ceil (-0.0) is -0.0. */ |
| 38 | if (signbitd (minus_zerod) && !signbitd (my_ceil (minus_zerod))) |
| 39 | result |= 1; |
| 40 | /* Test whether ceil (-0.3) is -0.0. */ |
| 41 | if (signbitd (-0.3) && !signbitd (my_ceil (-0.3))) |
| 42 | result |= 2; |
| 43 | return result; |
| 44 | } |
| 45 | ]])], |
| 46 | [gl_cv_func_ceil_ieee=yes], |
| 47 | [gl_cv_func_ceil_ieee=no], |
| 48 | [case "$host_os" in |
| 49 | # Guess yes on glibc systems. |
| 50 | *-gnu*) gl_cv_func_ceil_ieee="guessing yes" ;; |
| 51 | # If we don't know, assume the worst. |
| 52 | *) gl_cv_func_ceil_ieee="guessing no" ;; |
| 53 | esac |
| 54 | ]) |
| 55 | LIBS="$save_LIBS" |
| 56 | ]) |
| 57 | case "$gl_cv_func_ceil_ieee" in |
| 58 | *yes) ;; |
| 59 | *) REPLACE_CEIL=1 ;; |
| 60 | esac |
| 61 | fi |
| 62 | ]) |
| 63 | if test $REPLACE_CEIL = 1; then |
| 64 | dnl No libraries are needed to link lib/ceil.c. |
| 65 | CEIL_LIBM= |
| 66 | fi |
| 67 | AC_SUBST([CEIL_LIBM]) |
| 68 | ]) |
| 69 | |
| 70 | # Determines the libraries needed to get the ceil() function. |
| 71 | # Sets CEIL_LIBM. |
| 72 | AC_DEFUN([gl_FUNC_CEIL_LIBS], |
| 73 | [ |
| 74 | gl_CACHE_VAL_SILENT([gl_cv_func_ceil_libm], [ |
| 75 | gl_cv_func_ceil_libm=? |
| 76 | AC_LINK_IFELSE( |
| 77 | [AC_LANG_PROGRAM( |
| 78 | [[#ifndef __NO_MATH_INLINES |
| 79 | # define __NO_MATH_INLINES 1 /* for glibc */ |
| 80 | #endif |
| 81 | #include <math.h> |
| 82 | double x;]], |
| 83 | [[x = ceil(x);]])], |
| 84 | [gl_cv_func_ceil_libm=]) |
| 85 | if test "$gl_cv_func_ceil_libm" = "?"; then |
| 86 | save_LIBS="$LIBS" |
| 87 | LIBS="$LIBS -lm" |
| 88 | AC_LINK_IFELSE( |
| 89 | [AC_LANG_PROGRAM( |
| 90 | [[#ifndef __NO_MATH_INLINES |
| 91 | # define __NO_MATH_INLINES 1 /* for glibc */ |
| 92 | #endif |
| 93 | #include <math.h> |
| 94 | double x;]], |
| 95 | [[x = ceil(x);]])], |
| 96 | [gl_cv_func_ceil_libm="-lm"]) |
| 97 | LIBS="$save_LIBS" |
| 98 | fi |
| 99 | ]) |
| 100 | CEIL_LIBM="$gl_cv_func_ceil_libm" |
| 101 | ]) |