shithub: femtolisp

ref: 4dc8cff4fd04e8536f5577522ecb95032064f295
dir: /3rd/mp/test/gen.tab.c/

View raw version
#include "platform.h"
#include "mp.h"
#include "dat.h"
#include "fns.h"

static void
testcmp(void)
{
	int fail=0;
	int a, b;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			a=ldcmp(l2, l3);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			b=mpcmp(m2, m3);
			if(b<0) b=-1;
			if(b>0) b=1;
			if(a != b){
				fprintf(stderr, "FAIL: mpcmp(%s, %s): return value: got %d, expected %d\n", LFMT(l2), LFMT(l3), b, a);
				fail=1;
			}
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpcmp(%s, %s): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpcmp(%s, %s): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	if(!fail) fprintf(stderr, "mpcmp: passed\n");
	anyfail |= fail;
}
static void
testmagcmp(void)
{
	int fail=0;
	int a, b;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			a=ldmagcmp(l2, l3);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			b=mpmagcmp(m2, m3);
			if(b<0) b=-1;
			if(b>0) b=1;
			if(a != b){
				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): return value: got %d, expected %d\n", LFMT(l2), LFMT(l3), b, a);
				fail=1;
			}
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpmagcmp(%s, %s): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	if(!fail) fprintf(stderr, "mpmagcmp: passed\n");
	anyfail |= fail;
}
static void
testadd(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldadd(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpadd(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpadd(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpadd(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpadd(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpadd: passed\n");
	anyfail |= fail;
}
static void
testsub(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldsub(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpsub(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpsub(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpsub(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpsub(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpsub: passed\n");
	anyfail |= fail;
}
static void
testmagadd(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldmagadd(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagadd(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagadd(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagadd(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpmagadd(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpmagadd: passed\n");
	anyfail |= fail;
}
static void
testmagsub(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldmagsub(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagsub(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagsub(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpmagsub(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpmagsub(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpmagsub: passed\n");
	anyfail |= fail;
}
static void
testand(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldand(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpand(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpand(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpand(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpand(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpand: passed\n");
	anyfail |= fail;
}
static void
testbic(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldbic(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpbic(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpbic(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpbic(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpbic(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpbic: passed\n");
	anyfail |= fail;
}
static void
testor(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldor(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpor(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpor(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpor(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpor(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpor: passed\n");
	anyfail |= fail;
}
static void
testxor(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			ldxor(l2, l3, l4);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpxor(m2, m3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpxor(m2, m3, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mpxor(m2, m3, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpxor(%s, %s, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpxor: passed\n");
	anyfail |= fail;
}
static void
testnot(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		ldnot(l2, l3);
		ldtomp(l2, m2);
		mptarget(m3);
		mpnot(m2, m3);
		if(!ldmpeq(l2, m2)){
			fprintf(stderr, "FAIL: mpnot(%s, out): arg 1: input corrupted\n", LFMT(l2));
			fail=1;
		}
		if(m3->top == 0 && m3->sign < 0){
			fprintf(stderr, "FAIL: mpnot(%s, out): arg 2: got -0, shouldn't happen\n", LFMT(l2));
			fail=1;
		}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
			fprintf(stderr, "FAIL: mpnot(%s, out): arg 2: got denormalised result\n", LFMT(l2));
			fail=1;
		}else if(!ldmpeq(l3, m3)){
			fprintf(stderr, "FAIL: mpnot(%s, out): arg 2: got %s, expected %s\n", LFMT(l2), MFMT(m3), LFMT(l3));
			fail=1;
		}
		ldtomp(l2, m2);
		mptarget(m3);
		mpnot(m2, m2);
		if(m2->top == 0 && m2->sign < 0){
			fprintf(stderr, "FAIL: mpnot(%s, out): alias 2 and 1: arg 2: got -0, shouldn't happen\n", LFMT(l2));
			fail=1;
		}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
			fprintf(stderr, "FAIL: mpnot(%s, out): alias 2 and 1: arg 2: got denormalised result\n", LFMT(l2));
			fail=1;
		}else if(!ldmpeq(l3, m2)){
			fprintf(stderr, "FAIL: mpnot(%s, out): alias 2 and 1: arg 2: got %s, expected %s\n", LFMT(l2), MFMT(m2), LFMT(l3));
			fail=1;
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	if(!fail) fprintf(stderr, "mpnot: passed\n");
	anyfail |= fail;
}
static void
testleft(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=-128;i3<=128;i3++){
			ldleft(l2, i3, l4);
			ldtomp(l2, m2);
			mptarget(m4);
			mpleft(m2, i3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): arg 1: input corrupted\n", LFMT(l2), i3);
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			mptarget(m4);
			mpleft(m2, i3, m2);
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpleft(%s, %d, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m2), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpleft: passed\n");
	anyfail |= fail;
}
static void
testright(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=-128;i3<=128;i3++){
			ldright(l2, i3, l4);
			ldtomp(l2, m2);
			mptarget(m4);
			mpright(m2, i3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): arg 1: input corrupted\n", LFMT(l2), i3);
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			mptarget(m4);
			mpright(m2, i3, m2);
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpright(%s, %d, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m2), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpright: passed\n");
	anyfail |= fail;
}
static void
testasr(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=-128;i3<=128;i3++){
			ldasr(l2, i3, l4);
			ldtomp(l2, m2);
			mptarget(m4);
			mpasr(m2, i3, m4);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): arg 1: input corrupted\n", LFMT(l2), i3);
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m4), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			mptarget(m4);
			mpasr(m2, i3, m2);
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), i3);
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), i3);
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpasr(%s, %d, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), i3, MFMT(m2), LFMT(l4));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l4);
	mpfree(m4);
	if(!fail) fprintf(stderr, "mpasr: passed\n");
	anyfail |= fail;
}
static void
testdiv_(void)
{
	int fail=0;
	ldint *l2 = ldnew(0);
	mpint *m2 = mpnew(0);
	int i2;
	ldint *l3 = ldnew(0);
	mpint *m3 = mpnew(0);
	int i3;
	ldint *l4 = ldnew(0);
	mpint *m4 = mpnew(0);
	ldint *l5 = ldnew(0);
	mpint *m5 = mpnew(0);
	for(i2=0;i2<NTEST;i2++){
		testgen(i2, l2);
		for(i3=0;i3<NTEST;i3++){
			testgen(i3, l3);
			lddiv_(l2, l3, l4, l5);
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mptarget(m5);
			mpdiv_(m2, m3, m4, m5);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			if(m5->top == 0 && m5->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 4: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m5->top != 0 && m5->p[m5->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 4: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l5, m5)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): arg 4: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m5), LFMT(l5));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mptarget(m5);
			mpdiv_(m2, m3, m2, m5);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m5->top == 0 && m5->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 4: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m5->top != 0 && m5->p[m5->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 4: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l5, m5)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 4: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m5), LFMT(l5));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m2)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mptarget(m5);
			mpdiv_(m2, m3, m3, m5);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m5->top == 0 && m5->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 4: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m5->top != 0 && m5->p[m5->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 4: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l5, m5)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 4: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m5), LFMT(l5));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m3)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 3 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l4));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mptarget(m5);
			mpdiv_(m2, m3, m4, m2);
			if(!ldmpeq(l3, m3)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 2: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			if(m2->top == 0 && m2->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 4: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m2->top != 0 && m2->p[m2->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 4: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l5, m2)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 1: arg 4: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m2), LFMT(l5));
				fail=1;
			}
			ldtomp(l2, m2);
			ldtomp(l3, m3);
			mptarget(m4);
			mptarget(m5);
			mpdiv_(m2, m3, m4, m3);
			if(!ldmpeq(l2, m2)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 1: input corrupted\n", LFMT(l2), LFMT(l3));
				fail=1;
			}
			if(m4->top == 0 && m4->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 3: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m4->top != 0 && m4->p[m4->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 3: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l4, m4)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 3: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m4), LFMT(l4));
				fail=1;
			}
			if(m3->top == 0 && m3->sign < 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 4: got -0, shouldn't happen\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(m3->top != 0 && m3->p[m3->top - 1] == 0){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 4: got denormalised result\n", LFMT(l2), LFMT(l3));
				fail=1;
			}else if(!ldmpeq(l5, m3)){
				fprintf(stderr, "FAIL: mpdiv_(%s, %s, out, out): alias 4 and 2: arg 4: got %s, expected %s\n", LFMT(l2), LFMT(l3), MFMT(m3), LFMT(l5));
				fail=1;
			}
		}
	}
	ldfree(l2);
	mpfree(m2);
	ldfree(l3);
	mpfree(m3);
	ldfree(l4);
	mpfree(m4);
	ldfree(l5);
	mpfree(m5);
	if(!fail) fprintf(stderr, "mpdiv_: passed\n");
	anyfail |= fail;
}
void
tests(void)
{
	testcmp();
	testmagcmp();
	testadd();
	testsub();
	testmagadd();
	testmagsub();
	testand();
	testbic();
	testor();
	testxor();
	testnot();
	testleft();
	testright();
	testasr();
	testdiv_();
}