Merge pull request #13239 from s-hadinger/berry_nan

Berry support for NAN
This commit is contained in:
s-hadinger 2021-09-28 23:21:14 +02:00 committed by GitHub
commit 7ced37fdd6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 1742 additions and 1720 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,36 +1,38 @@
#include "be_constobj.h" #include "be_constobj.h"
static be_define_const_map_slots(m_libmath_map) { static be_define_const_map_slots(m_libmath_map) {
{ be_const_key(asin, 13), be_const_func(m_asin) }, { be_const_key(asin, 7), be_const_func(m_asin) },
{ be_const_key(acos, -1), be_const_func(m_acos) }, { be_const_key(isnan, -1), be_const_func(m_isnan) },
{ be_const_key(tanh, 5), be_const_func(m_tanh) }, { be_const_key(sinh, 22), be_const_func(m_sinh) },
{ be_const_key(atan2, -1), be_const_func(m_atan2) }, { be_const_key(cos, -1), be_const_func(m_cos) },
{ be_const_key(cos, 20), be_const_func(m_cos) },
{ be_const_key(pi, 24), be_const_real(M_PI) },
{ be_const_key(abs, 17), be_const_func(m_abs) },
{ be_const_key(sinh, -1), be_const_func(m_sinh) },
{ be_const_key(srand, -1), be_const_func(m_srand) },
{ be_const_key(cosh, -1), be_const_func(m_cosh) },
{ be_const_key(imax, 6), be_const_int(M_IMAX) },
{ be_const_key(floor, -1), be_const_func(m_floor) },
{ be_const_key(log, -1), be_const_func(m_log) },
{ be_const_key(exp, 22), be_const_func(m_exp) },
{ be_const_key(imin, 9), be_const_int(M_IMIN) },
{ be_const_key(ceil, 1), be_const_func(m_ceil) },
{ be_const_key(sin, 12), be_const_func(m_sin) },
{ be_const_key(rand, -1), be_const_func(m_rand) }, { be_const_key(rand, -1), be_const_func(m_rand) },
{ be_const_key(deg, -1), be_const_func(m_deg) },
{ be_const_key(log10, 16), be_const_func(m_log10) },
{ be_const_key(acos, -1), be_const_func(m_acos) },
{ be_const_key(cosh, -1), be_const_func(m_cosh) },
{ be_const_key(tanh, 21), be_const_func(m_tanh) },
{ be_const_key(rad, 11), be_const_func(m_rad) },
{ be_const_key(abs, -1), be_const_func(m_abs) },
{ be_const_key(atan2, -1), be_const_func(m_atan2) },
{ be_const_key(tan, 19), be_const_func(m_tan) },
{ be_const_key(ceil, 15), be_const_func(m_ceil) },
{ be_const_key(nan, -1), be_const_real(NAN) },
{ be_const_key(imin, -1), be_const_int(M_IMIN) },
{ be_const_key(pow, -1), be_const_func(m_pow) }, { be_const_key(pow, -1), be_const_func(m_pow) },
{ be_const_key(atan, -1), be_const_func(m_atan) }, { be_const_key(atan, -1), be_const_func(m_atan) },
{ be_const_key(imax, 25), be_const_int(M_IMAX) },
{ be_const_key(exp, 17), be_const_func(m_exp) },
{ be_const_key(log, 1), be_const_func(m_log) },
{ be_const_key(sqrt, -1), be_const_func(m_sqrt) }, { be_const_key(sqrt, -1), be_const_func(m_sqrt) },
{ be_const_key(deg, -1), be_const_func(m_deg) }, { be_const_key(srand, -1), be_const_func(m_srand) },
{ be_const_key(log10, -1), be_const_func(m_log10) }, { be_const_key(floor, -1), be_const_func(m_floor) },
{ be_const_key(rad, -1), be_const_func(m_rad) }, { be_const_key(sin, -1), be_const_func(m_sin) },
{ be_const_key(tan, -1), be_const_func(m_tan) }, { be_const_key(pi, 8), be_const_real(M_PI) },
}; };
static be_define_const_map( static be_define_const_map(
m_libmath_map, m_libmath_map,
25 27
); );
static be_define_const_module( static be_define_const_module(

View File

@ -34,6 +34,17 @@
#define mathfunc(func) func #define mathfunc(func) func
#endif #endif
static int m_isnan(bvm *vm)
{
if (be_top(vm) >= 1 && be_isreal(vm, 1)) {
breal x = be_toreal(vm, 1);
be_pushbool(vm, isnan(x));
} else {
be_pushbool(vm, bfalse);
}
be_return(vm);
}
static int m_abs(bvm *vm) static int m_abs(bvm *vm)
{ {
if (be_top(vm) >= 1 && be_isnumber(vm, 1)) { if (be_top(vm) >= 1 && be_isnumber(vm, 1)) {
@ -272,6 +283,7 @@ static int m_rand(bvm *vm)
#if !BE_USE_PRECOMPILED_OBJECT #if !BE_USE_PRECOMPILED_OBJECT
be_native_module_attr_table(math) { be_native_module_attr_table(math) {
be_native_module_function("isnan", m_isnan),
be_native_module_function("abs", m_abs), be_native_module_function("abs", m_abs),
be_native_module_function("ceil", m_ceil), be_native_module_function("ceil", m_ceil),
be_native_module_function("floor", m_floor), be_native_module_function("floor", m_floor),
@ -295,6 +307,7 @@ be_native_module_attr_table(math) {
be_native_module_function("srand", m_srand), be_native_module_function("srand", m_srand),
be_native_module_function("rand", m_rand), be_native_module_function("rand", m_rand),
be_native_module_real("pi", M_PI), be_native_module_real("pi", M_PI),
be_native_module_real("nan", NAN),
be_native_module_int("imax", M_IMAX), be_native_module_int("imax", M_IMAX),
be_native_module_int("imin", M_IMIN), be_native_module_int("imin", M_IMIN),
}; };
@ -303,6 +316,7 @@ be_define_native_module(math, NULL);
#else #else
/* @const_object_info_begin /* @const_object_info_begin
module math (scope: global, depend: BE_USE_MATH_MODULE) { module math (scope: global, depend: BE_USE_MATH_MODULE) {
isnan, func(m_isnan)
abs, func(m_abs) abs, func(m_abs)
ceil, func(m_ceil) ceil, func(m_ceil)
floor, func(m_floor) floor, func(m_floor)
@ -326,6 +340,7 @@ module math (scope: global, depend: BE_USE_MATH_MODULE) {
srand, func(m_srand) srand, func(m_srand)
rand, func(m_rand) rand, func(m_rand)
pi, real(M_PI) pi, real(M_PI)
nan, real(NAN)
imax, int(M_IMAX) imax, int(M_IMAX)
imin, int(M_IMIN) imin, int(M_IMIN)
} }