plan9port

fork of plan9port with libvec, libstr and libsdb
Log | Files | Refs | README | LICENSE

mpmod.c (256B)


      1 #include "os.h"
      2 #include <mp.h>
      3 #include "dat.h"
      4 
      5 /* remainder = b mod m */
      6 /* */
      7 /* knuth, vol 2, pp 398-400 */
      8 
      9 void
     10 mpmod(mpint *b, mpint *m, mpint *remainder)
     11 {
     12 	mpdiv(b, m, nil, remainder);
     13 	if(remainder->sign < 0)
     14 		mpadd(m, remainder, remainder);
     15 }