Subversion Repositories planix.SVN

Rev

Rev 33 | Details | Compare with Previous | 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
{
33 7u83 13
	if(b == nil){
2 - 14
		b = mpnew(0);
33 7u83 15
		setmalloctag(b, getcallerpc(&i));
16
	}
2 - 17
	*b->p = i;
33 7u83 18
	b->top = 1;
19
	b->sign = 1;
20
	return mpnorm(b);
2 - 21
}
22
 
23
uint
24
mptoui(mpint *b)
25
{
26
	uint x;
27
 
28
	x = *b->p;
29
	if(b->sign < 0)
30
		x = 0;
31
	else if(b->top > 1 || (sizeof(mpdigit) > sizeof(uint) && x > MAXUINT))
32
		x =  MAXUINT;
33
	return x;
34
}