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