Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
5a14a1d6
Commit
5a14a1d6
authored
11 years ago
by
Rachel Dowdall
Browse files
Options
Downloads
Patches
Plain Diff
Added various simple functions to math module.
parent
d02f6eaa
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/builtinmath.c
+36
-0
36 additions, 0 deletions
py/builtinmath.c
py/qstrdefs.h
+10
-0
10 additions, 0 deletions
py/qstrdefs.h
tests/basics/math.py
+49
-0
49 additions, 0 deletions
tests/basics/math.py
with
95 additions
and
0 deletions
py/builtinmath.c
+
36
−
0
View file @
5a14a1d6
...
...
@@ -40,6 +40,24 @@ MATH_FUN_1(acos, acos)
MATH_FUN_1
(
asin
,
asin
)
MATH_FUN_1
(
atan
,
atan
)
MATH_FUN_2
(
atan2
,
atan2
)
MATH_FUN_1
(
ceil
,
ceil
)
MATH_FUN_2
(
copysign
,
copysign
)
MATH_FUN_1
(
fabs
,
fabs
)
MATH_FUN_1
(
floor
,
floor
)
//TODO: delegate to x.__floor__() if x is not a float
MATH_FUN_2
(
fmod
,
fmod
)
//MATH_FUN_1(frexp, frexp)
MATH_FUN_1
(
isfinite
,
isfinite
)
MATH_FUN_1
(
isinf
,
isinf
)
MATH_FUN_1
(
isnan
,
isnan
)
MATH_FUN_1
(
trunc
,
trunc
)
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//MATH_FUN_1(, )
//TODO: factorial, fsum, frexp, ldexp, modf
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
)
},
...
...
@@ -65,6 +83,24 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_asin
),
(
mp_obj_t
)
&
mp_math_asin_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_atan
),
(
mp_obj_t
)
&
mp_math_atan_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_atan2
),
(
mp_obj_t
)
&
mp_math_atan2_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_ceil
),
(
mp_obj_t
)
&
mp_math_ceil_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_copysign
),
(
mp_obj_t
)
&
mp_math_copysign_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_fabs
),
(
mp_obj_t
)
&
mp_math_fabs_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_floor
),
(
mp_obj_t
)
&
mp_math_floor_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_fmod
),
(
mp_obj_t
)
&
mp_math_fmod_obj
},
//{ MP_OBJ_NEW_QSTR(MP_QSTR_frexp), (mp_obj_t)&mp_math_frexp_obj },
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_isfinite
),
(
mp_obj_t
)
&
mp_math_isfinite_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_isinf
),
(
mp_obj_t
)
&
mp_math_isinf_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_isnan
),
(
mp_obj_t
)
&
mp_math_isnan_obj
},
{
MP_OBJ_NEW_QSTR
(
MP_QSTR_trunc
),
(
mp_obj_t
)
&
mp_math_trunc_obj
},
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
//{ MP_OBJ_NEW_QSTR(MP_QSTR_), (mp_obj_t)&mp_math__obj },
};
STATIC
const
mp_map_t
mp_module_math_globals
=
{
...
...
This diff is collapsed.
Click to expand it.
py/qstrdefs.h
+
10
−
0
View file @
5a14a1d6
...
...
@@ -141,6 +141,16 @@ Q(acos)
Q
(
asin
)
Q
(
atan
)
Q
(
atan2
)
Q
(
ceil
)
Q
(
copysign
)
Q
(
fabs
)
Q
(
floor
)
Q
(
fmod
)
Q
(
frexp
)
Q
(
isfinite
)
Q
(
isinf
)
Q
(
isnan
)
Q
(
trunc
)
Q
(
mem_total
)
Q
(
mem_current
)
...
...
This diff is collapsed.
Click to expand it.
tests/basics/math.py
0 → 100644
+
49
−
0
View file @
5a14a1d6
# Tests the functions imported from math
from
math
import
*
test_values
=
[
-
100.
,
-
1.23456
,
-
1
,
-
0.5
,
0.0
,
0.5
,
1.23456
,
100.
]
p_test_values
=
[
0.1
,
0.5
,
1.23456
]
unit_range_test_values
=
[
-
1.
,
-
0.75
,
-
0.5
,
-
0.25
,
0.
,
0.25
,
0.5
,
0.75
,
1.
]
#IEEE_test_values = [1, 0, float('NaN'), float('Inf'), -float('NaN'), -float('Inf')]
#TODO: float('NaN')
functions
=
[(
sqrt
,
p_test_values
),
(
exp
,
test_values
),
(
expm1
,
test_values
),
(
log
,
p_test_values
),
(
log2
,
p_test_values
),
(
log10
,
p_test_values
),
(
cosh
,
test_values
),
(
sinh
,
test_values
),
(
tanh
,
test_values
),
(
acosh
,
[
1.0
,
5.0
,
1.0
]),
(
asinh
,
test_values
),
(
atanh
,
[
-
0.99
,
-
0.5
,
0.0
,
0.5
,
0.99
]),
(
cos
,
test_values
),
(
sin
,
test_values
),
(
tan
,
test_values
),
(
acos
,
unit_range_test_values
),
(
asin
,
unit_range_test_values
),
(
atan
,
test_values
),
(
ceil
,
test_values
),
(
fabs
,
test_values
),
(
floor
,
test_values
),
#(frexp, test_values),
#(isfinite, [1, 0, float('NaN'), float('Inf')])
(
trunc
,
test_values
)
]
for
function
,
test_vals
in
functions
:
for
value
in
test_vals
:
print
(
"
{:8.7f}
"
.
format
(
function
(
value
)))
binary_functions
=
[(
copysign
,
[(
23.
,
42.
),
(
-
23.
,
42.
),
(
23.
,
-
42.
),
(
-
23.
,
-
42.
),
(
1.
,
0.0
),
(
1.
,
-
0.0
)])
]
#for function, test_vals in binary_functions:
# for value1, value2 in test_vals:
# print("{:8.7f}".format(function(value1, value2)))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment