newLISP Fan Club

Forum => newLISP and the O.S. => Topic started by: alex on June 19, 2006, 02:00:57 PM

Title: a=b(mod c)
Post by: alex on June 19, 2006, 02:00:57 PM
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

??
Title:
Post by: alex on June 19, 2006, 02:05:56 PM
I am sorry - NOT NEGATIVE !
Title:
Post by: Lutz on June 19, 2006, 03:48:26 PM
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
Title:
Post by: William James on June 19, 2006, 09:57:15 PM
This will always give a non-negative result.
(define (%% m n , result)
  (set 'result (% m n))
  (+ result (if (< result 0) n 0)))
Title:
Post by: alex on June 20, 2006, 03:23:11 AM
Or(define (%% a b) (% (+ (% a b) b) b)):-)
Title:
Post by: William James on June 21, 2006, 04:34:49 PM
Very nice, but when running on a 6502 processor clocked at 1.79MHz that extra % will cost you.
Title:
Post by: HPW on June 21, 2006, 10:33:52 PM
Quoterunning on a 6502 processor clocked at 1.7


Do you have newLISP running on such a system?
Title:
Post by: William James on June 21, 2006, 10:54:26 PM
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.
Title:
Post by: HPW on June 22, 2006, 12:59:57 AM
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?
Title:
Post by: William James on June 22, 2006, 08:53:31 PM
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.)