Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
4ab128bb
Commit
4ab128bb
authored
Mar 22, 2014
by
Damien George
Browse files
Merge branch 'master' of github.com:micropython/micropython
parents
365274da
26a4506d
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/intdivmod.c
0 → 100644
View file @
4ab128bb
#include
"mpconfig.h"
machine_int_t
python_modulo
(
machine_int_t
dividend
,
machine_int_t
divisor
)
{
machine_int_t
lsign
=
(
dividend
>=
0
)
?
1
:-
1
;
machine_int_t
rsign
=
(
divisor
>=
0
)
?
1
:-
1
;
dividend
%=
divisor
;
if
(
lsign
!=
rsign
)
{
dividend
+=
divisor
;
}
return
dividend
;
}
machine_int_t
python_floor_divide
(
machine_int_t
num
,
machine_int_t
denom
)
{
machine_int_t
lsign
=
num
>
0
?
1
:
-
1
;
machine_int_t
rsign
=
denom
>
0
?
1
:
-
1
;
if
(
lsign
==
-
1
)
{
num
*=
-
1
;}
if
(
rsign
==
-
1
)
{
denom
*=
-
1
;}
if
(
lsign
!=
rsign
){
return
-
(
num
+
denom
-
1
)
/
denom
;
}
else
{
return
num
/
denom
;
}
}
py/intdivmod.h
0 → 100644
View file @
4ab128bb
// Functions for integer modulo and floor division
machine_int_t
python_modulo
(
machine_int_t
dividend
,
machine_int_t
divisor
);
machine_int_t
python_floor_divide
(
machine_int_t
num
,
machine_int_t
denom
);
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment