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
#define VLDIGITS (sizeof(vlong)/sizeof(mpdigit))
6
 
7
/*
8
 *  this code assumes that a vlong is an integral number of
9
 *  mpdigits long.
10
 */
11
mpint*
12
uvtomp(uvlong v, mpint *b)
13
{
14
	int s;
15
 
33 7u83 16
	if(b == nil){
17
		b = mpnew(VLDIGITS*Dbits);
18
		setmalloctag(b, getcallerpc(&v));
19
	}else
20
		mpbits(b, VLDIGITS*Dbits);
21
	b->sign = 1;
22
	for(s = 0; s < VLDIGITS; s++){
2 - 23
		b->p[s] = v;
24
		v >>= sizeof(mpdigit)*8;
25
	}
26
	b->top = s;
33 7u83 27
	return mpnorm(b);
2 - 28
}
29
 
30
uvlong
31
mptouv(mpint *b)
32
{
33
	uvlong v;
34
	int s;
35
 
33 7u83 36
	if(b->top == 0 || b->sign < 0)
2 - 37
		return 0LL;
38
 
39
	if(b->top > VLDIGITS)
33 7u83 40
		return -1LL;
2 - 41
 
42
	v = 0ULL;
43
	for(s = 0; s < b->top; s++)
44
		v |= (uvlong)b->p[s]<<(s*sizeof(mpdigit)*8);
45
 
46
	return v;
47
}