Remove MICROPY_FLOAT_CONST from ULAB_DEFINE_FLOAT_CONST

A given use of ULAB_DEFINE_FLOAT_CONST may already have the correct form
of the float constant, so wrapping it in MICROPY_FLOAT_CONST may be the
wrong thing to do.  So let the user of ULAB_DEFINE_FLOAT_CONST control how
the constant is formed.

Signed-off-by: Damien George <damien.p.george@gmail.com>
This commit is contained in:
Damien George 2022-07-11 15:13:05 +10:00
parent 770ae31556
commit 35b58d0037
5 changed files with 9 additions and 9 deletions

View file

@ -47,7 +47,7 @@
// Use ULAB_REFERENCE_FLOAT_CONST to reference a constant float object in code.
#define ULAB_DEFINE_FLOAT_CONST(id, num, hex32, hex64) \
const mp_obj_float_t id##_obj = {{&mp_type_float}, MICROPY_FLOAT_CONST(num)}
const mp_obj_float_t id##_obj = {{&mp_type_float}, (num)}
#define ULAB_REFERENCE_FLOAT_CONST(id) MP_ROM_PTR(&id##_obj)

View file

@ -25,7 +25,7 @@
//| """Numerical approximation methods"""
//|
ULAB_DEFINE_FLOAT_CONST(approx_trapz_dx, 1.0, 0x3f800000UL, 0x3ff0000000000000ULL);
ULAB_DEFINE_FLOAT_CONST(approx_trapz_dx, MICROPY_FLOAT_CONST(1.0), 0x3f800000UL, 0x3ff0000000000000ULL);
#if ULAB_NUMPY_HAS_INTERP
//| def interp(

View file

@ -676,7 +676,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(create_linspace_obj, 2, create_linspace);
//| ...
//|
ULAB_DEFINE_FLOAT_CONST(const_ten, 10.0, 0x41200000UL, 0x4024000000000000ULL);
ULAB_DEFINE_FLOAT_CONST(const_ten, MICROPY_FLOAT_CONST(10.0), 0x41200000UL, 0x4024000000000000ULL);
mp_obj_t create_logspace(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
static const mp_arg_t allowed_args[] = {

View file

@ -57,19 +57,19 @@
// math constants
#if ULAB_NUMPY_HAS_E
ULAB_DEFINE_FLOAT_CONST(ulab_const_float_e, MP_E+0., 0x402df854UL, 0x4005bf0a8b145769ULL);
ULAB_DEFINE_FLOAT_CONST(ulab_const_float_e, MP_E, 0x402df854UL, 0x4005bf0a8b145769ULL);
#endif
#if ULAB_NUMPY_HAS_INF
ULAB_DEFINE_FLOAT_CONST(numpy_const_float_inf, (mp_float_t)INFINITY+0., 0x7f800000UL, 0x7ff0000000000000ULL);
ULAB_DEFINE_FLOAT_CONST(numpy_const_float_inf, (mp_float_t)INFINITY, 0x7f800000UL, 0x7ff0000000000000ULL);
#endif
#if ULAB_NUMPY_HAS_NAN
ULAB_DEFINE_FLOAT_CONST(numpy_const_float_nan, (mp_float_t)NAN+0., 0x7fc00000UL, 0x7ff8000000000000ULL);
ULAB_DEFINE_FLOAT_CONST(numpy_const_float_nan, (mp_float_t)NAN, 0x7fc00000UL, 0x7ff8000000000000ULL);
#endif
#if ULAB_NUMPY_HAS_PI
ULAB_DEFINE_FLOAT_CONST(ulab_const_float_pi, (mp_float_t)MP_PI+0., 0x40490fdbUL, 0x400921fb54442d18ULL);
ULAB_DEFINE_FLOAT_CONST(ulab_const_float_pi, MP_PI, 0x40490fdbUL, 0x400921fb54442d18ULL);
#endif
static const mp_rom_map_elem_t ulab_numpy_globals_table[] = {

View file

@ -22,8 +22,8 @@
#include "../../ulab_tools.h"
#include "optimize.h"
ULAB_DEFINE_FLOAT_CONST(xtolerance, 2.4e-7, 0x3480d959UL, 0x3e901b2b29a4692bULL);
ULAB_DEFINE_FLOAT_CONST(rtolerance, 0.0, 0UL, 0ULL);
ULAB_DEFINE_FLOAT_CONST(xtolerance, MICROPY_FLOAT_CONST(2.4e-7), 0x3480d959UL, 0x3e901b2b29a4692bULL);
ULAB_DEFINE_FLOAT_CONST(rtolerance, MICROPY_FLOAT_CONST(0.0), 0UL, 0ULL);
static mp_float_t optimize_python_call(const mp_obj_type_t *type, mp_obj_t fun, mp_float_t x, mp_obj_t *fargs, uint8_t nparams) {
// Helper function for calculating the value of f(x, a, b, c, ...),