Commit 50c025fb authored by Matthieu Schaller's avatar Matthieu Schaller
Browse files

Add an implementation of the sincos() function (absent on OSX) that is used in...

Add an implementation of the sincos() function (absent on OSX) that is used in the COLIBRE fork of the project.
parent 837efd3b
......@@ -1382,6 +1382,17 @@ if test "$ax_cv_c_compiler_vendor" = "clang"; then
AC_CHECK_LIB([m],[__exp10f], [AC_DEFINE([HAVE___EXP10F],1,[The __exp10f function is present.])])
fi
# Check if we have native sincos and sincosf functions. If not failback to our
# implementations. On Apple/CLANG we have __sincos, so also check for that
# if the compiler is clang.
AC_CHECK_LIB([m],[sincos], [AC_DEFINE([HAVE_SINCOS],1,[The sincos function is present.])])
AC_CHECK_LIB([m],[sincosf], [AC_DEFINE([HAVE_SINCOSF],1,[The sincosf function is present.])])
if test "$ax_cv_c_compiler_vendor" = "clang"; then
AC_CHECK_LIB([m],[__sincos], [AC_DEFINE([HAVE___SINCOS],1,[The __sincos function is present.])])
AC_CHECK_LIB([m],[__sincosf], [AC_DEFINE([HAVE___SINCOSF],1,[The __sincosf function is present.])])
fi
# Add warning flags by default, if these can be used. Option =error adds
# -Werror to GCC, clang and Intel. Note do this last as compiler tests may
# become errors, if that's an issue don't use CFLAGS for these, use an AC_SUBST().
......
......@@ -52,7 +52,7 @@ include_HEADERS = space.h runner.h queue.h task.h lock.h cell.h part.h const.h \
chemistry.h chemistry_io.h chemistry_struct.h cosmology.h restart.h space_getsid.h utilities.h \
mesh_gravity.h cbrt.h exp10.h velociraptor_interface.h swift_velociraptor_part.h outputlist.h \
logger_io.h tracers_io.h tracers.h tracers_struct.h star_formation_io.h fof.h fof_struct.h fof_io.h \
multipole.h multipole_struct.h \
multipole.h multipole_struct.h sincos.h \
star_formation_struct.h star_formation.h star_formation_iact.h \
star_formation_logger.h star_formation_logger_struct.h \
pressure_floor.h pressure_floor_struct.h pressure_floor_iact.h \
......
/*******************************************************************************
* This file is part of SWIFT.
* Copyright (c) 2020 Matthieu Schaller (schaller@strw.leidenuniv.nl)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
******************************************************************************/
#ifndef SWIFT_SINCOS_H
#define SWIFT_SINCOS_H
/* Config parameters. */
#include "../config.h"
/* Some standard headers. */
#include <math.h>
/* Local headers. */
#include "inline.h"
#if !defined(HAVE_SINCOS) && !defined(HAVE___SINCOS)
/**
* @brief Compute both the sin() and cos() of a number.
*
* This function is only used as a replacement for compilers that do
* not implement GNU extensions to the C language.
*
* @param x The input value.
* @param sin (return) The sine of x.
* @param cos (return) The cosine of x.
*/
__attribute__((always_inline)) INLINE static void sincos(const double x,
double *sin,
double *cos) {
*sin = sin(x);
*cos = cos(x);
}
#endif
#if !defined(HAVE_SINCOSF) && !defined(HAVE___SINCOSF)
/**
* @brief Compute both the sin() and cos() of a number.
*
* This function is only used as a replacement for compilers that do
* not implement GNU extensions to the C language.
*
* @param x The input value.
* @param sin (return) The sine of x.
* @param cos (return) The cosine of x.
*/
__attribute__((always_inline)) INLINE static void sincosf(const float x,
float *sin,
float *cos) {
*sin = sinf(x);
*cos = cosf(x);
}
#endif
/* Use the __sincos and __sincosf versions if needed. */
#if !defined(HAVE_SINCOS) && defined(HAVE___SINCOS)
#define sincos(x, s, c) __sincos(x, s, c)
#endif
#if !defined(HAVE_SINCOSF) && defined(HAVE___SINCOSF)
#define sincosf(x, s, c) __sincosf(x, s, c)
#endif
#endif /* SWIFT_SINCOS_H */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment