Re: Question on large integer software

New Message Reply About this list Date view Thread view Subject view Author view

Mark Tillotson (markt@harlequin.co.uk)
Tue, 28 Jul 1998 12:54:13 +0100


Jay Sulzberger <jays@panix.com> wrote:
| One of the charming things about most Schemes is that doing

most Schemes and all Common Lisps...

You still have to code up useful modulus operations though:

(defun modexp (a power modulus)
  (cond ((= power 1) a)
        ((= power 0) 1)
        (t (let* ((rec (modexp a (ash power -1) modulus))
                   (sqr (mod (* rec rec) modulus))
                   )
              (if (oddp power)
                  (mod (* a sqr) modulus)
                sqr)))))

(modexp
 98390566430963746051203723659363494128734798423042437104756634014728348124023768295769237423078237
 83475675987477582903489465904398204283504732085905730495832490584390849058904854958439058208934984
185669082387243898959072386749438723827289783449685790983240128482401234723122514017502570474939393)

=>

 95317076925363759280758109699701089817363118283266685984600029021130898192888619687392404070761046

(OK, the recursion is a bit heavy on stack use, so you'd want an
iterative version really).

__Mark
[ markt@harlequin.co.uk | http://www.harlequin.co.uk/ | +44(0)1954 785433 ]
[ personal homepage http://utter.chaos.org.uk/~markt/ | fax " " 785444 ]


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Fri Aug 21 1998 - 17:20:58 ADT