git: 9front

ref: 5cd5d8899f0ca0f3d9c6b56d7feabfa0729df88c
dir: /sys/src/cmd/unix/drawterm/libmp/mpmod.c/

View raw version
#include "os.h"
#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);
}