aboutsummaryrefslogtreecommitdiff
path: root/src/libmp/port/mpmod.c
blob: 91bebfa2727a66fb200787b700e9ce89a216c93a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#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);
}