Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable gamma, drem on macOS #2775

Merged
merged 1 commit into from
Jul 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/builtin.c
Original file line number Diff line number Diff line change
Expand Up @@ -107,28 +107,31 @@ static jv f_plus(jq_state *jq, jv input, jv a, jv b) {
#ifdef __APPLE__
// macOS has a bunch of libm deprecation warnings, so let's clean those up
#ifdef HAVE_TGAMMA
#define HAVE_GAMMA
#define gamma tgamma
#endif
#ifdef HAVE___EXP10
#define HAVE_EXP10
#define exp10 __exp10
#endif
#ifdef HAVE_REMAINDER
#define HAVE_DREM
#define drem remainder
#endif

// We replace significand with our own, since there's not a rename-replacement
#ifdef HAVE_FREXP
#define HAVE_CUSTOM_SIGNIFICAND
static double __jq_significand(double x) {
int z;
return 2*frexp(x, &z);
}
#define HAVE_SIGNIFICAND
#define significand __jq_significand
#elif defined(HAVE_SCALBN) && defined(HAVE_ILOGB)
#define HAVE_CUSTOM_SIGNIFICAND
static double __jq_significand(double x) {
return scalbn(x, -ilogb(x));
}
#define HAVE_SIGNIFICAND
#define significand __jq_significand
#endif

Expand Down Expand Up @@ -1876,7 +1879,10 @@ static const char jq_builtins[] =
#undef LIBM_DD

#ifdef __APPLE__
#undef HAVE_CUSTOM_SIGNIFICAND
#undef HAVE_GAMMA
#undef HAVE_EXP10
#undef HAVE_DREM
#undef HAVE_SIGNIFICAND
#endif

static block gen_builtin_list(block builtins) {
Expand Down
4 changes: 2 additions & 2 deletions src/libm.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ LIBM_DD(erfc)
#else
LIBM_DD_NO(erfc)
#endif
#if (defined(HAVE_EXP10) && !defined(WIN32)) || (defined(__APPLE__) && defined(HAVE___EXP10))
#if defined(HAVE_EXP10) && !defined(WIN32)
LIBM_DD(exp10)
#else
LIBM_DD_NO(exp10)
Expand Down Expand Up @@ -274,7 +274,7 @@ LIBM_DDD(scalbln)
#else
LIBM_DDD_NO(scalbln)
#endif
#if defined(HAVE_CUSTOM_SIGNIFICAND) || (defined(HAVE_SIGNIFICAND) && !defined(WIN32))
#if defined(HAVE_SIGNIFICAND) && !defined(WIN32)
LIBM_DD(significand)
#else
LIBM_DD_NO(significand)
Expand Down