Skip to content
Myr

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

3 files+59 added−15 removed

modified:src/builtin.c+56 added-3 removed
148 unmodified lines
149#undef LIBM_DDDD150#undef LIBM_DDD151#undef LIBM_DD152153#ifdef HAVE_FREXP154static 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_MODF166static 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_R177static 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#endif187188static 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 lines
1468#define LIBM_DDDD_NO(name)14691470static 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 lines
1609/* 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;16271628#undef LIBM_DDDD_NO1629#undef LIBM_DDD_NO
54 unmodified lines
modified:src/libm.h-10 removed
212 unmodified lines
213LIBM_DDD(fmod)214#else215LIBM_DDD_NO(fmod)216#endif217#ifdef HAVE_FREXP218LIBM_DDD(frexp)219#else220LIBM_DDD_NO(frexp)221#endif217#ifdef HAVE_GAMMA218LIBM_DD(gamma)219#else220LIBM_DD_NO(gamma)
12 unmodified lines
233LIBM_DD(logb)234#else235LIBM_DD_NO(logb)236#endif242#ifdef HAVE_MODF243LIBM_DDD(modf)244#else245LIBM_DDD_NO(modf)246#endif237#ifdef HAVE_NEARBYINT238LIBM_DD(nearbyint)239#else240LIBM_DD_NO(nearbyint)
51 unmodified lines
modified:configure.ac+3 added-2 removed
172 unmodified lines
173AC_CHECK_MATH_FUNC(fma,[.5,1.0,1.5])174AC_CHECK_MATH_FUNC(fmax,[.5,1.0])175AC_CHECK_MATH_FUNC(fmin,[.5,1.0])176AC_CHECK_MATH_FUNC(fmod,[.5,1.0])177AC_CHECK_MATH_FUNC(frexp,[.5,1.0])177AC_FIND_FUNC([frexp], [m c], [#include <math.h>], [0, 0])178AC_CHECK_MATH_FUNC(gamma,[.5])179AC_CHECK_MATH_FUNC(hypot, [.5,.5])180AC_CHECK_MATH_FUNC(j0, [.5])181AC_CHECK_MATH_FUNC(j1, [.5])
3 unmodified lines
185AC_CHECK_MATH_FUNC(log1p,[.5])186AC_CHECK_MATH_FUNC(log2, [.5])187AC_CHECK_MATH_FUNC(log, [.5])188AC_CHECK_MATH_FUNC(logb,[.5])189AC_CHECK_MATH_FUNC(modf,[.5,1.0])189AC_FIND_FUNC([modf], [m c], [#include <math.h>], [0, 0])190AC_FIND_FUNC([lgamma_r], [m c], [#include <math.h>], [0, 0])191AC_CHECK_MATH_FUNC(nearbyint,[.5])192AC_CHECK_MATH_FUNC(nextafter,[.5,1.0])193AC_CHECK_MATH_FUNC(nexttoward,[.5,1.0])194AC_CHECK_MATH_FUNC(pow10,[.5])
87 unmodified lines