Fix frexp, modf, lgamma_r (fix #1374)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Nicolas Williams · committed by Nicolas Williams · parent 7935d30 · Browse files · 3 files·+59 added−15 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+59 added−15 removed
- other:+59 added−15 removed
Provenance
- Commit
71d4ff6- Tree
111a5c2- Author
Nicolas Williams <nico@cryptonector.com>- Committer
Nicolas Williams <nico@cryptonector.com>- Parent
7935d30
3 files changed+59 added−15 removed
modified:src/builtin.c+56 added-3 removed
148 unmodified lines149 #undef LIBM_DDDD150 #undef LIBM_DDD151 #undef LIBM_DD152 153+#ifdef HAVE_FREXP154+static jv f_frexp(jq_state *jq, jv input) {155+ if (jv_get_kind(input) != JV_KIND_NUMBER) {156+ return type_error(input, "number required");157+ }158+ int exp;159+ double d = frexp(jv_number_value(input), &exp);160+ jv ret = JV_ARRAY(jv_number(d), jv_number(exp));161+ jv_free(input);162+ return ret;163+}164+#endif165+#ifdef HAVE_MODF166+static jv f_modf(jq_state *jq, jv input) {167+ if (jv_get_kind(input) != JV_KIND_NUMBER) {168+ return type_error(input, "number required");169+ }170+ double i;171+ jv ret = JV_ARRAY(jv_number(modf(jv_number_value(input), &i)));172+ jv_free(input);173+ return jv_array_append(ret, jv_number(i));174+}175+#endif176+#ifdef HAVE_LGAMMA_R177+static jv f_lgamma_r(jq_state *jq, jv input) {178+ if (jv_get_kind(input) != JV_KIND_NUMBER) {179+ return type_error(input, "number required");180+ }181+ int sign;182+ jv ret = JV_ARRAY(jv_number(lgamma_r(jv_number_value(input), &sign)));183+ jv_free(input);184+ return jv_array_append(ret, jv_number(sign));185+}186+#endif187+188 static jv f_negate(jq_state *jq, jv input) {189 if (jv_get_kind(input) != JV_KIND_NUMBER) {190 return type_error(input, "cannot be negated");191 }1276 unmodified lines1468 #define LIBM_DDDD_NO(name)1469 1470 static const struct cfunction function_list[] = {1471 #include "libm.h"1472+#ifdef HAVE_FREXP1473+ {(cfunction_ptr)f_frexp,"frexp", 1},1474+#endif1475+#ifdef HAVE_MODF1476+ {(cfunction_ptr)f_modf,"modf", 1},1477+#endif1478+#ifdef HAVE_LGAMMA_R1479+ {(cfunction_ptr)f_lgamma_r,"lgamma_r", 1},1480+#endif1481 {(cfunction_ptr)f_plus, "_plus", 3},1482 {(cfunction_ptr)f_negate, "_negate", 1},1483 {(cfunction_ptr)f_minus, "_minus", 3},1484 {(cfunction_ptr)f_multiply, "_multiply", 3},124 unmodified lines1609 /* Include unsupported math functions next */1610 #define LIBM_DD(name)1611 #define LIBM_DDD(name)1612 #define LIBM_DDDD(name)1569-#define LIBM_DD_NO(name) "def " #name ": \"Error: " #name "() not found at build time\"|error;"1570-#define LIBM_DDD_NO(name) "def " #name "(a;b): \"Error: " #name "() not found at build time\"|error;"1571-#define LIBM_DDDD_NO(name) "def " #name "(a;b;c): \"Error: " #name "() not found at build time\"|error;"1613+#define LIBM_DD_NO(name) "def " #name ": \"Error: " #name "/0 not found at build time\"|error;"1614+#define LIBM_DDD_NO(name) "def " #name "(a;b): \"Error: " #name "/2 not found at build time\"|error;"1615+#define LIBM_DDDD_NO(name) "def " #name "(a;b;c): \"Error: " #name "/3 not found at build time\"|error;"1616 #include "libm.h"1617+#ifndef HAVE_FREXP1618+ "def frexp: \"Error: frexp/0 not found found at build time\"|error;"1619+#endif1620+#ifndef HAVE_MODF1621+ "def modf: \"Error: modf/0 not found found at build time\"|error;"1622+#endif1623+#ifndef HAVE_LGAMMA_R1624+ "def lgamma_r: \"Error: lgamma_r/0 not found found at build time\"|error;"1625+#endif1626 ;1627 1628 #undef LIBM_DDDD_NO1629 #undef LIBM_DDD_NO54 unmodified linesmodified:src/libm.h-10 removed
212 unmodified lines213 LIBM_DDD(fmod)214 #else215 LIBM_DDD_NO(fmod)216 #endif217-#ifdef HAVE_FREXP218-LIBM_DDD(frexp)219-#else220-LIBM_DDD_NO(frexp)221-#endif217 #ifdef HAVE_GAMMA218 LIBM_DD(gamma)219 #else220 LIBM_DD_NO(gamma)12 unmodified lines233 LIBM_DD(logb)234 #else235 LIBM_DD_NO(logb)236 #endif242-#ifdef HAVE_MODF243-LIBM_DDD(modf)244-#else245-LIBM_DDD_NO(modf)246-#endif237 #ifdef HAVE_NEARBYINT238 LIBM_DD(nearbyint)239 #else240 LIBM_DD_NO(nearbyint)51 unmodified linesmodified:configure.ac+3 added-2 removed
172 unmodified lines173 AC_CHECK_MATH_FUNC(fma,[.5,1.0,1.5])174 AC_CHECK_MATH_FUNC(fmax,[.5,1.0])175 AC_CHECK_MATH_FUNC(fmin,[.5,1.0])176 AC_CHECK_MATH_FUNC(fmod,[.5,1.0])177-AC_CHECK_MATH_FUNC(frexp,[.5,1.0])177+AC_FIND_FUNC([frexp], [m c], [#include <math.h>], [0, 0])178 AC_CHECK_MATH_FUNC(gamma,[.5])179 AC_CHECK_MATH_FUNC(hypot, [.5,.5])180 AC_CHECK_MATH_FUNC(j0, [.5])181 AC_CHECK_MATH_FUNC(j1, [.5])3 unmodified lines185 AC_CHECK_MATH_FUNC(log1p,[.5])186 AC_CHECK_MATH_FUNC(log2, [.5])187 AC_CHECK_MATH_FUNC(log, [.5])188 AC_CHECK_MATH_FUNC(logb,[.5])189-AC_CHECK_MATH_FUNC(modf,[.5,1.0])189+AC_FIND_FUNC([modf], [m c], [#include <math.h>], [0, 0])190+AC_FIND_FUNC([lgamma_r], [m c], [#include <math.h>], [0, 0])191 AC_CHECK_MATH_FUNC(nearbyint,[.5])192 AC_CHECK_MATH_FUNC(nextafter,[.5,1.0])193 AC_CHECK_MATH_FUNC(nexttoward,[.5,1.0])194 AC_CHECK_MATH_FUNC(pow10,[.5])87 unmodified lines