a=b(mod c)

Started by alex, June 19, 2006, 02:00:57 PM

Previous topic - Next topic

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

??

alex

#1
I am sorry - NOT NEGATIVE !

Lutz

#2
There are various ways to look at this, see http://en.wikipedia.org/wiki/Remainder">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

William James

#3
This will always give a non-negative result.
(define (%% m n , result)
  (set 'result (% m n))
  (+ result (if (< result 0) n 0)))

alex

#4
Or(define (%% a b) (% (+ (% a b) b) b)):-)

William James

#5
Very nice, but when running on a 6502 processor clocked at 1.79MHz that extra % will cost you.

HPW

#6
Quoterunning on a 6502 processor clocked at 1.7


Do you have newLISP running on such a system?
Hans-Peter

William James

#7
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.

HPW

#8
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?
Hans-Peter

William James

#9
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.)