Subversion Repositories planix.SVN

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#include "os.h"
2
#include <mp.h>
3
#include "dat.h"
4
 
5
/*
6
 *  this code assumes that mpdigit is at least as
7
 *  big as an int.
8
 */
9
 
10
mpint*
11
uitomp(uint i, mpint *b)
12
{
13
	if(b == nil)
14
		b = mpnew(0);
15
	mpassign(mpzero, b);
16
	if(i != 0)
17
		b->top = 1;
18
	*b->p = i;
19
	return b;
20
}
21
 
22
uint
23
mptoui(mpint *b)
24
{
25
	uint x;
26
 
27
	x = *b->p;
28
	if(b->sign < 0)
29
		x = 0;
30
	else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint) && x > MAXUINT))
31
		x =  MAXUINT;
32
	return x;
33
}