[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Modulus in Applesoft



-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

In <eYE8d.259383$%n4.21465@bignews6.bellsouth.net> Jayson Smith wrote:
> I'm having problems using the Modulus operator under Applesoft, or 
> don't know how to do it.  In Integer, if I remember correctly, you 
> could do, E.G. 10 poke 493,x mod 256:poke 494,x/256 and have a memory 
> address poked in.  That's just an example.  However, doing print 900 
> mod 256 in Applesoft produces the result 9000, and I think I just 
> figured out why. I think it's printing the number 900, then the 
> contents of variable 'mod' which is 0.  So how do you do that in 
> Applesoft? Thanks.

I always used something like this to find x mod y:

abs(x)-int(abs(x)/y)*y

If you know x will always be non-negative, you can leave out the two
occurrences of abs() and speed things up a bit.

  _/_
 / v \ Scott Alfter (remove the obvious to send mail)
(IIGS( http://alfter.us/            Top-posting!
 \_^_/ rm -rf /bin/laden            >What's the most annoying thing on Usenet?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Linux)

iD8DBQFBZtJ2VgTKos01OwkRAtQhAJ91lukSMekfBDUTUfotYQ6ihtld4gCgsyTh
s5LyglT8AdUv0lclgfID/MI=
=0xj2
-----END PGP SIGNATURE-----