Browse Source

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

pull/1522/head
Damien George 9 years ago
parent
commit
7e359c648b
  1. 10
      py/modcmath.c
  2. 10
      py/modmath.c
  3. 9
      py/obj.h
  4. 8
      py/objfloat.c

10
py/modcmath.c

@ -35,12 +35,6 @@
/// The `cmath` module provides some basic mathematical funtions for
/// 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)
/// Returns the phase of the number `z`, in the range (-pi, +pi].
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);
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_e), (mp_obj_t)&mp_math_e_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_pi), (mp_obj_t)&mp_math_pi_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_e), mp_const_float_e },
{ 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_polar), (mp_obj_t)&mp_cmath_polar_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_rect), (mp_obj_t)&mp_cmath_rect_obj },

10
py/modmath.c

@ -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_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)
/// Returns the square root of `x`.
MATH_FUN_1(sqrt, sqrt)
@ -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[] = {
{ 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_pi), (mp_obj_t)&mp_math_pi_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_e), mp_const_float_e },
{ 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_pow), (mp_obj_t)&mp_math_pow_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_exp), (mp_obj_t)&mp_math_exp_obj },

9
py/obj.h

@ -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
// float
typedef struct _mp_obj_float_t {
mp_obj_base_t base;
mp_float_t value;
} mp_obj_float_t;
#define mp_const_float_e ((mp_obj_t)&mp_const_float_e_obj)
#define mp_const_float_pi ((mp_obj_t)&mp_const_float_pi_obj)
extern const struct _mp_obj_float_t mp_const_float_e_obj;
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)
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

8
py/objfloat.c

@ -39,6 +39,14 @@
#include <math.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) {
(void)kind;
mp_obj_float_t *o = o_in;

Loading…
Cancel
Save