Commit 7e359c64 authored by Damien George's avatar Damien George

py: Move float e/pi consts to objfloat and make mp_obj_float_t private.

parent aaef1851
...@@ -35,12 +35,6 @@ ...@@ -35,12 +35,6 @@
/// The `cmath` module provides some basic mathematical funtions for /// The `cmath` module provides some basic mathematical funtions for
/// working with complex numbers. /// working with complex numbers.
// These are defined in modmath.c
/// \constant e - base of the natural logarithm
extern const mp_obj_float_t mp_math_e_obj;
/// \constant pi - the ratio of a circle's circumference to its diameter
extern const mp_obj_float_t mp_math_pi_obj;
/// \function phase(z) /// \function phase(z)
/// Returns the phase of the number `z`, in the range (-pi, +pi]. /// Returns the phase of the number `z`, in the range (-pi, +pi].
STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) {
...@@ -132,8 +126,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin); ...@@ -132,8 +126,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin);
STATIC const mp_map_elem_t mp_module_cmath_globals_table[] = { STATIC const mp_map_elem_t mp_module_cmath_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_cmath) }, { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_cmath) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_e), (mp_obj_t)&mp_math_e_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_e), mp_const_float_e },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pi), (mp_obj_t)&mp_math_pi_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_pi), mp_const_float_pi },
{ MP_OBJ_NEW_QSTR(MP_QSTR_phase), (mp_obj_t)&mp_cmath_phase_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_phase), (mp_obj_t)&mp_cmath_phase_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_polar), (mp_obj_t)&mp_cmath_polar_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_polar), (mp_obj_t)&mp_cmath_polar_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_rect), (mp_obj_t)&mp_cmath_rect_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_rect), (mp_obj_t)&mp_cmath_rect_obj },
......
...@@ -52,12 +52,6 @@ ...@@ -52,12 +52,6 @@
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { mp_int_t x = MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj)); return mp_obj_new_int(x); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
// These are also used by cmath.c
/// \constant e - base of the natural logarithm
const mp_obj_float_t mp_math_e_obj = {{&mp_type_float}, M_E};
/// \constant pi - the ratio of a circle's circumference to its diameter
const mp_obj_float_t mp_math_pi_obj = {{&mp_type_float}, M_PI};
/// \function sqrt(x) /// \function sqrt(x)
/// Returns the square root of `x`. /// Returns the square root of `x`.
MATH_FUN_1(sqrt, sqrt) MATH_FUN_1(sqrt, sqrt)
...@@ -188,8 +182,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); ...@@ -188,8 +182,8 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees);
STATIC const mp_map_elem_t mp_module_math_globals_table[] = { STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_math) }, { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_math) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_e), (mp_obj_t)&mp_math_e_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_e), mp_const_float_e },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pi), (mp_obj_t)&mp_math_pi_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_pi), mp_const_float_pi },
{ MP_OBJ_NEW_QSTR(MP_QSTR_sqrt), (mp_obj_t)&mp_math_sqrt_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_sqrt), (mp_obj_t)&mp_math_sqrt_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pow), (mp_obj_t)&mp_math_pow_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_pow), (mp_obj_t)&mp_math_pow_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&mp_math_exp_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&mp_math_exp_obj },
......
...@@ -564,10 +564,11 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, mp_uint_ ...@@ -564,10 +564,11 @@ void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, mp_uint_
#if MICROPY_PY_BUILTINS_FLOAT #if MICROPY_PY_BUILTINS_FLOAT
// float // float
typedef struct _mp_obj_float_t { #define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
mp_obj_base_t base; #define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
mp_float_t value; extern const struct _mp_obj_float_t mp_const_float_e_obj;
} mp_obj_float_t; extern const struct _mp_obj_float_t mp_const_float_pi_obj;
#define mp_obj_is_float(o) MP_OBJ_IS_TYPE((o), &mp_type_float) #define mp_obj_is_float(o) MP_OBJ_IS_TYPE((o), &mp_type_float)
mp_float_t mp_obj_float_get(mp_obj_t self_in); mp_float_t mp_obj_float_get(mp_obj_t self_in);
mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
......
...@@ -39,6 +39,14 @@ ...@@ -39,6 +39,14 @@
#include <math.h> #include <math.h>
#include "py/formatfloat.h" #include "py/formatfloat.h"
typedef struct _mp_obj_float_t {
mp_obj_base_t base;
mp_float_t value;
} mp_obj_float_t;
const mp_obj_float_t mp_const_float_e_obj = {{&mp_type_float}, M_E};
const mp_obj_float_t mp_const_float_pi_obj = {{&mp_type_float}, M_PI};
STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
(void)kind; (void)kind;
mp_obj_float_t *o = o_in; mp_obj_float_t *o = o_in;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment