code: 9ferno

ref: b548687a8ed1d0a159c9d3f3f921d93bbb56908e
dir: /libmp/port/mpmod.c/

View raw version
#include "os.h"
#include "../include/mp.h"
#include "dat.h"

// remainder = b mod m
//
// knuth, vol 2, pp 398-400

void
mpmod(mpint *b, mpint *m, mpint *remainder)
{
	mpdiv(b, m, nil, remainder);
	if(remainder->sign < 0)
		mpadd(m, remainder, remainder);
}