Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
7e359c64
Commit
7e359c64
authored
Aug 20, 2015
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py: Move float e/pi consts to objfloat and make mp_obj_float_t private.
parent
aaef1851
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
17 additions
and
20 deletions
+17
-20
py/modcmath.c
py/modcmath.c
+2
-8
py/modmath.c
py/modmath.c
+2
-8
py/obj.h
py/obj.h
+5
-4
py/objfloat.c
py/objfloat.c
+8
-0
No files found.
py/modcmath.c
View file @
7e359c64
...
...
@@ -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
},
...
...
py/modmath.c
View file @
7e359c64
...
...
@@ -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
},
...
...
py/obj.h
View file @
7e359c64
...
...
@@ -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
...
...
py/objfloat.c
View file @
7e359c64
...
...
@@ -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
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment