ftp.nice.ch/pub/next/developer/languages/lisp/AKCL.1.599.s.tar.gz#/akcl-1-599/V/c/num_log.c

This is num_log.c in view mode; [Download] [Up]

Changes file for /usr/local/src/kcl/./c/num_log.c
Created on Sat Feb 23 18:40:26 1991
Usage \n@s[Original text\n@s|Replacement Text\n@s]
See the file rascal.ics.utexas.edu:/usr2/ftp/merge.c
for a program to merge change files.  Anything not between
"\n@s[" and  "\n@s]" is a simply a comment.
This file was constructed using emacs and  merge.el
Enhancements Copyright (c) W. Schelter All rights reserved.
   by (Bill Schelter)  wfs@carl.ma.utexas.edu 


****Change:(orig (12 12 c))
@s[#include "num_include.h"


@s|#include "num_include.h"
#include "mp.h"

@s]


****Change:(orig (18 18 a))
@s[	fixnum or bignum ( not normalized )
*/

@s|	fixnum or bignum ( not normalized )
*/

object big_log_op();


@s]


****Change:(orig (25 25 c))
@s[	struct bignum *big_log_op();

@s|	

@s]


****Change:(orig (43 43 a))
@s[	x = (object)copy_to_big(vs_base[0]);
	vs_push(x);
	i = 1;

@s|	x = (object)copy_to_big(vs_base[0]);
	vs_push(x);
	i = 1;
	{save_avma;

@s]


****Change:(orig (47 47 a))
@s[		x = (object)big_log_op(x, vs_base[i], op);
		i++;
	}

@s|		x = (object)big_log_op(x, vs_base[i], op);
		i++;
	}
	 restore_avma;}

@s]


****Change:(orig (54 54 a))
@s[	x and y, and return the result in x destructively.

@s|	x and y, and return the result in x destructively.

	

@s]


****Change:(orig (56 66 d))
@s[struct bignum *
big_log_op(x, y, op)
struct bignum *x;
object y;

@s,	int	end_x, end_y;
	int	i, j;

@s|
@s]


****Change:(orig (68 89 c))
@s[	r = x;		/* remember start of x */
	if (type_of(x) != t_bignum)
		FEwrong_type_argument(Sbignum, x);
	else if (big_sign(x) < 0) {

@s,		FEwrong_type_argument(Sinteger, y);

@s|void minimize_lg(x)
GEN x;
{int j,i,lgx = lgef(x);
 GEN u = x+2;
 i = lgx;
 i -= 2;
 while (-- i >= 0)
   { if (*u++) break;
   }
 j = lgx -i -3;
 if (j)
   { GEN v = x+2;
     GEN w = v + j;
     GEN lim = x+lgx;
     while (w<lim)
       {*v++ = *w++;}
     setlgef(x,(i+3));}
 if (i==-1) setsigne(x,0);
}

@s]


****Change:(orig (91 124 d))
@s[	end_x = end_y = 0;
	while ((end_x == 0) || (end_y == 0)) {
		if (end_x == 0)
			i = (x->big_car) & MASK;

@s,	x->big_car |= ((*op)(sign_x, sign_y) & ~MASK);

@s|
@s]


****Change:(orig (126 126 c))
@s[
	return(r);

@s|
/* Fix this.   Should be destructive into x0.
   It is for the benefit of log_op;
   Maybe write an mp version, and then do it.
*/   

GEN
complementi(x)
     GEN x;
{int l = lgef(x);
 GEN u = cgeti(l);
 unsigned long * v ;
 unsigned long *w ;

 MP_START_LOW(w,(unsigned long *)x,l);
 MP_START_LOW(v,(unsigned long *)u,l);
 setlgef(u,l);
 setsigne(u,1);
 l -= MP_CODE_WORDS;
 {unsigned int next=0;
  while (--l >=0)
    { unsigned int last = MP_NEXT_UP(w);
      MP_NEXT_UP(v) = next - last ;
       if (last > next)
	 { next -= 1 ;}}
  return u;}}
 
object big_log_op(x0,y0,op)
object x0,y0;
 long (*op)();     
{ int leadx,leady;
  int result_length;
  int lgx,lgy;
  GEN x,y,u,up,result;
  save_avma;
  x = MP(x0);
  y = (type_of(y0)==t_bignum ? MP(y0) : stoi(fix(y0)));
  leadx = signe(x);
  lgx=lgef(x);
  if (leadx < 0)
    x = complementi(x);
  else leadx = 0;

  lgy = lgef(y);
  leady = signe(y);
  if (leady < 0)
    y=complementi(y);
  else leady = 0;
  result_length = (lgx > lgy ? lgx : lgy);
  u = result = cgeti(result_length);
  setlgef(result,result_length);
  MP_START_LOW(u,u,result_length);
  result_length -= MP_CODE_WORDS;

  x += lgx;
  y += lgy;
  lgx -= MP_CODE_WORDS;
  lgy -= MP_CODE_WORDS;

  while (--lgx >= 0)
    { if (--lgy >= 0)
	{ MP_NEXT_UP(u) = (*op)(MP_NEXT_UP(x),MP_NEXT_UP(y));}
    else MP_NEXT_UP(u) = (*op)(MP_NEXT_UP(x),leady);
      }
  /*  lgx is now 0 */
  while (--lgy >= 0)
    {  MP_NEXT_UP(u) = (*op)(leadx,MP_NEXT_UP(y));}
  {int leadresult = (*op)(leadx,leady);
   if (leadresult < 0)
     { result = complementi(result);
       setsigne(result,-1);}
   else setsigne(result,1);}
  minimize_lg(result);
  restore_avma;
  gcopy_to_big(result,x0);
  return x0;

@s]


****Change:(orig (127 127 a))
@s[}

@s|}
   

@s]


****Change:(orig (239 255 c))
@s[{
	int	sign, cell, bit, i;

	if (p >= 0) {

@s,		return((x->big.big_car >> bit) & 1);
	} else
		return(0);

@s|{ GEN u = MP(x);
  int ans ;
  int i = p /32;
  if (signe(u) < 0)
    {  save_avma;
       u = complementi(u);
       restore_avma;
   }
  if (i < lgef(u))
    { ans = ((MP_ITH_WORD(u,i,lgef(u))) & (1 << p%32));}
  else if (big_sign(x) < 0) ans = 1;
  else ans = 0;
  return ans;

@s]


****Change:(orig (278 278 c))
@s[	for (i=0; i < 31; i++) count += ((x >> i) & 1);

@s|	for (i=0; i <= 31; i++) count += ((x >> i) & 1);

@s]


****Change:(orig (292 302 c))
@s[	} else if (type_of(x) == t_bignum) {
		count = 0;
		sign = big_sign(x);
		for (;;) {

@s,			x = (object)x->big.big_cdr;
		}
	} else

@s|	} else if (type_of(x) == t_bignum)
	  { save_avma;
	    GEN u = MP(x);
	    if (signe(u) < 0)
	      { u = subsi(-1,u);}
	    count = 0;
	    {int leng = lgef(u);
	     MP_START_LOW(u,u,leng);
	     leng -= MP_CODE_WORDS;
	     while (--leng >= 0)
	       { count += count_int_bits(MP_NEXT_UP(u));}}
	    restore_avma;
	  }
	  else

@s]


****Change:(orig (312 314 d))
@s[double_shift(h, l, w, hp, lp)
int	h, l, w, *hp, *lp;
{

@s|
@s]


****Change:(orig (316 325 d))
@s[	if (w >= 0) {
		*lp = (l << w) & MASK;
		*hp = ((h << w) & MASK) | ((l & MASK) >> (31 - w));
	} else {

@s,		*lp = ((h << (31 - w)) & MASK) | ((l & MASK) >> w);
	}
}


@s|
@s]


****Change:(orig (330 419 c))
@s[{
	struct bignum *y, *y0;
	object	r;
	int	cell, bits, sign, i;

@s,	r = normalize_big_to_object(y0);
	vs_reset;
	return(r);

@s|{ GEN u ;
  
  if (type_of(x) == t_fixnum)
    { if (w <= 0) return make_fixnum (fix(x) >> (-w));
      MPOP(return, shifti,stoi(fix(x)),w);
    }
  else
    if (type_of(x) == t_bignum)
      MPOP(return, shifti,MP(x),w);
  else
    	FEwrong_type_argument(Sinteger, x);
    

@s]


****Change:(orig (421 421 c))
@s[}


@s|}
  

@s]


****Change:(orig (429 429 c))
@s[	for (j = 0; j < 31 ; j++)

@s|	for (j = 0; j <= 31 ; j++)

@s]


****Change:(orig (433 433 a))
@s[		if (((i >> j) & 1) == 1) count = j + 1;
	return(count);
}


@s|		if (((i >> j) & 1) == 1) count = j + 1;
	return(count);
}




@s]


****Change:(orig (588 588 c))
@s[	vs_top = vs_base;
	if (i == 1)

@s|	vs_top = vs_base;
	if (i)

@s]


****Change:(orig (662 662 d))
@s[	int	count, cell, i;

	check_arg(1);
	check_type_integer(&vs_base[0]);

@s|	int	count, cell, i;

	check_arg(1);

@s]


****Change:(orig (668 678 c))
@s[	} else if (type_of(x) == t_bignum) {
		cell = 0;
		while(x->big.big_cdr != NULL) {
			cell++;

@s,		count = cell * 31 + int_bit_length(i);
	} else
		;

@s|	} else if (type_of(x) == t_bignum) 
	  { GEN w,u = MP(x);
	    int l = lg(u);
	    ulong high;
	    w = u;
	    MP_START_HIGH(u,u,l);
	    high = MP_NEXT_DOWN(u);
	    count = int_bit_length(high) ;
	    
	    l -= MP_CODE_WORDS;
	    
	    if (signe(w) < 0 &&
		high == (1 << (count -1)))
	      /* in the case of -(1<< n)
		 it is one less */
	      { int ll = l;
		int nzero = 0;
		while (--ll > 0)
		  { if (MP_NEXT_DOWN(u))
		      {nzero= 1; break;}}
		if (nzero == 0) --count ;}
		
	    count +=               32* (l - 1);
	  }
	else
	      	FEwrong_type_argument(Sinteger, x);

@s]


****Change:(orig (682 682 a))
@s[	vs_push(make_fixnum(count));
}


@s|	vs_push(make_fixnum(count));
}

#define W_SIZE (8*sizeof(int))
object
bitand(a,b,c)
     object a,b,c;
{ int d= a->bv.bv_fillp;
  int *ap,*bp,*cp;
  d=(d+W_SIZE-1)/W_SIZE;
  ap= (int *)(a->bv.bv_self);
  bp= (int *)(b->bv.bv_self);
  cp= (int *)(c->bv.bv_self);
  while (--d >= 0)
    { *cp++ = *bp++ & *ap++;
    }
  return c;
}

@s]


****Change:(orig (684 684 c))
@s[
object Sbit;

@s|
object
bitior(a,b,c)
     object a,b,c;
{ int *ap,*cp,*bp, d= a->bv.bv_fillp;
  d=(d+W_SIZE-1)/W_SIZE;
   ap= (int *)((a->bv.bv_self));
   bp= (int *)(b->bv.bv_self);
   cp= (int *)(c->bv.bv_self);
  while (--d >= 0)
    { *cp++ = *bp++ | *ap++;
    }
  return c;
}

/* Note in order to be equal we assume that the part above the
   fill pointer is 0 up to the next word */

bvequal(a,b)
     object a,b;
{ int *ap,*bp, d= a->bv.bv_fillp;
  d=(d+W_SIZE-1)/W_SIZE;
 ap= (int *)(a->bv.bv_self);
 bp= (int *)(b->bv.bv_self);
  while (--d >= 0)
    { if (*ap++ != *bp++) return 1;
    }
  return 0;
}

  


@s]

These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.