summaryrefslogtreecommitdiff
path: root/sys/src/libmp/test/main.c
blob: bf2ac6ec2855392011c49de8ce327f645afb9369 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#include <u.h>
#include <libc.h>
#include <mp.h>
#include "dat.h"
#include "fns.h"

static int
mpdetfmt(Fmt *f)
{
	mpint *a;
	int i, j;
	
	a = va_arg(f->args, mpint *);
	fmtprint(f, "(sign=%d,top=%d,size=%d,", a->sign, a->top, a->size);
	for(i=0;i<a->top;){
		fmtprint(f, "%ullx", (uvlong)a->p[i]);
		if(++i == a->top) break;
		fmtrune(f, ',');
		for(j = i+1; j < a->top;  j++)
			if(a->p[i] != a->p[j])
				goto next;
		fmtprint(f, "...");
		break;
	next:;
	}
	fmtrune(f, '|');
	for(i=a->top;i<a->size;){
		fmtprint(f, "%ullx", (uvlong)a->p[i]);
		if(++i == a->size) break;
		fmtrune(f, ',');
		for(j = i+1; j < a->top;  j++)
			if(a->p[i] != a->p[j])
				goto next2;
		fmtprint(f, "...");
		break;
	next2:;
	}
	fmtrune(f, ')');
	return 0;
}

void
main()
{
	extern int ldfmt(Fmt *);

	fmtinstall('B', mpfmt);
	fmtinstall(L'β', mpdetfmt);
	fmtinstall('L', ldfmt);
	
	convtests();
	tests();
}