a=b(mod c)
a=b(mod c)
I knew from my scool, that
1=1(mod 5)
6=1(mod 5)
-1=4(mod 5)
-3=2(mod 5)
and result MUST BE POSITIV !
Why in newlisp
(% -3 5) => -3
and
(mod -2 5) => -2
??
1=1(mod 5)
6=1(mod 5)
-1=4(mod 5)
-3=2(mod 5)
and result MUST BE POSITIV !
Why in newlisp
(% -3 5) => -3
and
(mod -2 5) => -2
??
There are various ways to look at this, see http://en.wikipedia.org/wiki/Remainder
newLISP behaves like 'C' or Pascal in this case. '%' and 'mod' in newLISP work like the underlying 'C' library routines: '%=' and 'fmod()'
Lutz
newLISP behaves like 'C' or Pascal in this case. '%' and 'mod' in newLISP work like the underlying 'C' library routines: '%=' and 'fmod()'
Lutz
-
- Posts: 58
- Joined: Sat Jun 10, 2006 5:34 am
This will always give a non-negative result.
Code: Select all
(define (%% m n , result)
(set 'result (% m n))
(+ result (if (< result 0) n 0)))
Or:-)
Code: Select all
(define (%% a b) (% (+ (% a b) b) b))
-
- Posts: 58
- Joined: Sat Jun 10, 2006 5:34 am
-
- Posts: 58
- Joined: Sat Jun 10, 2006 5:34 am
-
- Posts: 58
- Joined: Sat Jun 10, 2006 5:34 am