Skip to content

Commit

Permalink
Merge pull request #555 from cffk/c99-math-test
Browse files Browse the repository at this point in the history
Add tests for C99 math functions, hypot, atanh, cbrt, etc.

-DHAVE_C99_MATH=1 is provided if these functions are available.  This
will be used by the next release of geodesic.c.
  • Loading branch information
cffk committed Aug 13, 2017
2 parents 945e247 + 3b36c73 commit c489464
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
22 changes: 22 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,28 @@ if (HAVE_PTHREAD_MUTEX_RECURSIVE_DEFN)
add_definitions(-DHAVE_PTHREAD_MUTEX_RECURSIVE=1)
endif()

include (CheckCSourceCompiles)
if (MSVC)
set (CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} /WX")
else ()
set (CMAKE_REQUIRED_LIBRARIES m)
set (CMAKE_REQUIRED_FLAGS "${CMAKE_C_FLAGS} -Werror")
endif ()
# Check whether the C99 math function: hypot, atanh, etc. are available.
check_c_source_compiles (
"#include <math.h>
int main() {
int q;
return (int)(hypot(3.0, 4.0) + atanh(0.8) + cbrt(8.0) +
remquo(100.0, 90.0, &q) +
remainder(100.0, 90.0) + copysigna(1.0, -0.0));
}\n" C99_MATH)
if (C99_MATH)
add_definitions (-DHAVE_C99_MATH=1)
else ()
add_definitions (-DHAVE_C99_MATH=0)
endif ()

boost_report_value(PROJ_PLATFORM_NAME)
boost_report_value(PROJ_COMPILER_NAME)

Expand Down
14 changes: 14 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,20 @@ CFLAGS="$save_CFLAGS"
dnl We check for headers
AC_HEADER_STDC

dnl Check for C99 math functions
save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall -Werror"
AC_MSG_CHECKING([for C99 math functions])
AC_LINK_IFELSE([AC_LANG_PROGRAM(
[#include <math.h>],
[int q;
return (int)(hypot(3.0, 4.0) + atanh(0.8) + cbrt(8.0) +
remquo(100.0, 90.0, &q) +
remainder(100.0, 90.0) + copysign(1.0, -0.0));])],
[AC_MSG_RESULT([yes]);C99_MATH="-DHAVE_C99_MATH=1"],
[AC_MSG_RESULT([no]);C99_MATH="-DHAVE_C99_MATH=0"])
CFLAGS="$save_CFLAGS $C99_MATH"

AC_CHECK_FUNC(localeconv, [AC_DEFINE(HAVE_LOCALECONV,1,[Define to 1 if you have localeconv])])

dnl ---------------------------------------------------------------------------
Expand Down

0 comments on commit c489464

Please sign in to comment.