1# modf.m4 serial 9 2dnl Copyright (C) 2011-2021 Free Software Foundation, Inc. 3dnl This file is free software; the Free Software Foundation 4dnl gives unlimited permission to copy and/or distribute it, 5dnl with or without modifications, as long as this notice is preserved. 6 7AC_DEFUN([gl_FUNC_MODF], 8[ 9 m4_divert_text([DEFAULTS], [gl_modf_required=plain]) 10 AC_REQUIRE([gl_MATH_H_DEFAULTS]) 11 12 dnl Determine MODF_LIBM. 13 gl_MATHFUNC([modf], [double], [(double, double *)]) 14 15 m4_ifdef([gl_FUNC_MODF_IEEE], [ 16 if test $gl_modf_required = ieee && test $REPLACE_MODF = 0; then 17 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles 18 AC_CACHE_CHECK([whether modf works according to ISO C 99 with IEC 60559], 19 [gl_cv_func_modf_ieee], 20 [ 21 save_LIBS="$LIBS" 22 LIBS="$LIBS $MODF_LIBM" 23 AC_RUN_IFELSE( 24 [AC_LANG_SOURCE([[ 25#ifndef __NO_MATH_INLINES 26# define __NO_MATH_INLINES 1 /* for glibc */ 27#endif 28#include <math.h> 29]gl_DOUBLE_MINUS_ZERO_CODE[ 30]gl_DOUBLE_SIGNBIT_CODE[ 31/* Compare two numbers with ==. 32 This is a separate function because IRIX 6.5 "cc -O" miscompiles an 33 'x == x' test. */ 34static int 35numeric_equal (double x, double y) 36{ 37 return x == y; 38} 39static double dummy (double x, double *iptr) { return 0; } 40double zero; 41double minus_one = - 1.0; 42int main (int argc, char *argv[]) 43{ 44 double (* volatile my_modf) (double, double *) = argc ? modf : dummy; 45 int result = 0; 46 double i; 47 double f; 48 /* Test modf(NaN,...). 49 This test fails on NetBSD 5.1, Cygwin. */ 50 f = my_modf (zero / zero, &i); 51 if (numeric_equal (f, f)) 52 result |= 1; 53 /* Test modf(-Inf,...). 54 This test fails on FreeBSD 6.4, OpenBSD 6.7, IRIX 6.5, OSF/1 5.1. */ 55 f = my_modf (minus_one / zero, &i); 56 if (!(f == 0.0) || (signbitd (minus_zerod) && !signbitd (f))) 57 result |= 2; 58 return result; 59} 60 ]])], 61 [gl_cv_func_modf_ieee=yes], 62 [gl_cv_func_modf_ieee=no], 63 [case "$host_os" in 64 # Guess yes on glibc systems. 65 *-gnu* | gnu*) gl_cv_func_modf_ieee="guessing yes" ;; 66 # Guess yes on musl systems. 67 *-musl*) gl_cv_func_modf_ieee="guessing yes" ;; 68 # Guess yes on MSVC, no on mingw. 69 mingw*) AC_EGREP_CPP([Known], [ 70#ifdef _MSC_VER 71 Known 72#endif 73 ], 74 [gl_cv_func_modf_ieee="guessing yes"], 75 [gl_cv_func_modf_ieee="guessing no"]) 76 ;; 77 # If we don't know, obey --enable-cross-guesses. 78 *) gl_cv_func_modf_ieee="$gl_cross_guess_normal" ;; 79 esac 80 ]) 81 LIBS="$save_LIBS" 82 ]) 83 case "$gl_cv_func_modf_ieee" in 84 *yes) ;; 85 *) REPLACE_MODF=1 ;; 86 esac 87 fi 88 ]) 89 if test $REPLACE_MODF = 1; then 90 dnl Find libraries needed to link lib/modf.c. 91 AC_REQUIRE([gl_FUNC_TRUNC]) 92 MODF_LIBM="$TRUNC_LIBM" 93 fi 94]) 95