Skip to content

Commit

Permalink
change division of integers to return integers not floats kevinlawler…
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinlawler committed Nov 21, 2011
1 parent daf52eb commit 535c3ef
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion va.c
Expand Up @@ -94,12 +94,23 @@ K negate(K x){K y,z; U(y=Ki(0)) z=minus(y,x); cd(y); R z;} //TODO: probably impl
K divide(K a, K b)//NB: Integral values promoted to float
{
SCALAR_INIT(2)
if(1==zt*zt)zt*=2;
//if(1==zt*zt)zt*=2;//don't do because I%I is now I
K z=newK(zt,zn);U(z)

F u,d,y=FI;//nUmerator, Denominator, infinitY
//TODO:nulls;is it necessary to check for inf? IEEE may handle it already everywhere
//TODO: ensure that 1/inf==0 and 1/-inf ==0

I s,t,w=II;

if(1==ABS(at) && 1==ABS(bt))//save I from being cast to F for greater accuracy
{
if (an==bn) { DO(zn,s= kI(a)[i];t=kI(b)[i];kI(z)[i]=!t?!s?0:s>0?w:-w:s/t)}
else if (an==1) { DO(zn,s= kI(a)[0];t=kI(b)[i];kI(z)[i]=!t?!s?0:s>0?w:-w:s/t)}
else /* bn==1 */ { DO(zn,s= kI(a)[i];t=kI(b)[0];kI(z)[i]=!t?!s?0:s>0?w:-w:s/t)}
R z;
}

#define FDIVIDE kF(z)[i]=!d?!u?0:u>0?y:-y:u/d //0/0=0, 1/0=oo, -1/0=-oo, 1/2=0.5
SCALAR_EXPR(FDIVIDE,divide,u,d)

Expand Down

0 comments on commit 535c3ef

Please sign in to comment.