Currently, J's implementation of | for complex numbers is inconsistent with the implementation for reals. Compare:

   5 | 0 1 2 3 4
0 1 2 3 4
   }: 5 | 0 1 2 3 4,1j1
0 1 2 _2 _1

The definition of complex remainder is in jz.c:

ZF2(jtzrem){D a,b,d;Z q;
 if(ZEZ(u))R v;
 ZASSERT(!ZINF(v),EVNAN);
 if(INF(u.re)&&!u.im&&!v.im){
  if(u.re==inf )R 0<=v.re?v:u;
  if(u.re==infm)R 0>=v.re?v:u;
 }
 ZASSERT(!ZINF(u),EVNONCE);
 d=u.re*u.re+u.im*u.im;
 a=u.re*v.re+u.im*v.im; q.re=tfloor(0.5+a/d); 
 b=u.re*v.im-u.im*v.re; q.im=tfloor(0.5+b/d);
 R zminus(v,ztymes(u,q));
}

Changing q.re=tfloor(0.5+a/d); and q.im=tfloor(0.5+b/d) to q.re=tfloor(a/d) and q.im=tfloor(b/d) fixes this behavior.

Note that since complex #: calls complex |, this effects similar changes to antibase.


Contributed by MarshallLochbaum.

MarshallLochbaum/Complex Mod (last edited 2012-01-22 20:51:27 by MarshallLochbaum)