Page 1 of 1

a=b(mod c)

Posted: Mon Jun 19, 2006 9:00 pm
by alex
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
??

Posted: Mon Jun 19, 2006 9:05 pm
by alex
I am sorry - NOT NEGATIVE !

Posted: Mon Jun 19, 2006 10:48 pm
by Lutz
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

Posted: Tue Jun 20, 2006 4:57 am
by William James
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)))

Posted: Tue Jun 20, 2006 10:23 am
by alex
Or

Code: Select all

(define (%% a b) (% (+ (% a b) b) b))
:-)

Posted: Wed Jun 21, 2006 11:34 pm
by William James
Very nice, but when running on a 6502 processor clocked at 1.79MHz that extra % will cost you.

Posted: Thu Jun 22, 2006 5:33 am
by HPW
running on a 6502 processor clocked at 1.7
Do you have newLISP running on such a system?

Posted: Thu Jun 22, 2006 5:54 am
by William James
I haven't used my Atari 800XL in ages, but I use my Commodore 64 monitor to watch television; its chroma and luminance inputs accept S-video via a customized cable.

Posted: Thu Jun 22, 2006 7:59 am
by HPW
I have also an old C64 standing around in my workplace.

But your post gave the impression, that you run newLISP on a aged hardware. Was this impression wrong?

Posted: Fri Jun 23, 2006 3:53 am
by William James
I was only joking. (If you have a working C64 monitor, try running S-video from a DVD player to its chroma and luminance inputs; the picture is very clear.)