franz/lam8.c
/*
 *	(*invmod '<number> '<modulus>)
 * This function returns the inverse of  <number>
 * mod <modulus> in balanced representation
 * It is used in vaxima as a speed enhancement.
 */
(*invmod ' ')
This function returns the inverse of  
mod  in balanced representation
It is used in vaxima as a speed enhancement.
( * invmod ' ' ) This function returns the inverse of mod in balanced representation It is used in vaxima as a speed enhancement .
static lispval
Ibalmod(invmodp)
{
	register long mod_div_2, number, modulus;
	chkarg(2,"*mod");
	if ((TYPE(lbot->val) == INT) && (TYPE(lbot[1].val) == INT))
	{
		modulus = lbot[1].val->i;
		if(invmodp) number = invmod(lbot->val->i , modulus);
		else number = lbot->val->i % modulus;
		mod_div_2 = modulus / 2;
		if (number < 0)
		{
			if (number < (-mod_div_2))
				number += modulus;
		}
		else
		{
			if (number > mod_div_2)
				number -= modulus;
		}
		return( inewint(number) );
	}
	else
		error("*mod: Arguments must be fixnums", FALSE);
}
static lispval Ibalmod ( invmodp ) { register long mod_div_2 , number , modulus ; chkarg ( 2 , " " ) ; if ( ( TYPE ( lbot -> val ) == INT ) && ( TYPE ( lbot [ 1 ] . val ) == INT ) ) { modulus = lbot [ 1 ] . val -> i ; if ( invmodp ) number = invmod ( lbot -> val -> i , modulus ) ; else number = lbot -> val -> i % modulus ; mod_div_2 = modulus / 2 ; if ( number < 0 ) { if ( number < ( - mod_div_2 ) ) number += modulus ; } else { if ( number > mod_div_2 ) number -= modulus ; } return ( inewint ( number ) ) ; } else error ( " " , FALSE ) ; }
(*invmod '<number> '<modulus>)
 This function returns the inverse of  <number>
 mod <modulus> in balanced representation
 It is used in vaxima as a speed enhancement.
( * invmod ' <number > ' <modulus > ) This function returns the inverse of <number > mod <modulus > in balanced representation It is used in vaxima as a speed enhancement .
/* NOTREACHED */