use Structures: all; use SimplePrint: all; /* * Now, the dirty trick for providing the basics we need: */ /* % Dyadic Scalar Function kernel macro definitions % Function names are defined as: % {valence, jsymbol, compute type, result type} % Having result type available will let us support things like % int*int where we know result will be integer, rather than being % required to support double_real result. 1996-05-05 */ /* x plus y */ #define dplusBBI(XV,YV) (toi(XV)+toi(YV)) #define dplusBII(XV,YV) (toi(XV)+YV) #define dplusIBI(XV,YV) (XV+toi(YV)) #define dplusIII(XV,YV) (XV+YV) #define dplusDDD(XV,YV) (XV+YV) #define dplusBDD(XV,YV) (tod(XV)+YV) #define dplusDBD(XV,YV) (XV+tod(YV)) #define dplusIDD(XY,YV) (tod(XV)+YV) #define dplusDID(XV,YV) (XV+tod(YV)) /* x minus y */ #define dbarBBI(XV,YV) (toi(XV)-toi(YV)) #define dbarIBI(XV,YV) (XV-toi(YV)) #define dbarBII(XV,YV) (XV-YV) #define dbarIII(XV,YV) (XV-YV) #define dbarIDD(XV,YV) (tod(XV)-YV) #define dbarDID(XV,YV) (XV-tod(YV)) #define dbarDDD(XV,YV) (XV-YV) #define dbarBDD(XV,YV) (tod(XV)-YV) #define dbarDBD(XV,YV) (XV-tod(YV)) /* x times y */ #define dmpyBBB(XV,YV) (XV&YV) #define dmpyIII(XV,YV) (XV*YV) #define dmpyDDD(XV,YV) (XV*YV) #define dmpyBII(XV,YV) (toi(XV)*YV) #define dmpyIBI(XV,YV) (XV*toi(YV)) #define dmpyBDD(XV,YV) (tod(XV)*YV) #define dmpyDBD(XV,YV) (XV*tod(YV)) #define dmpyDID(XV,YV) (XV*tod(YV)) #define dmpyIDD(XV,YV) (tod(XV)*YV) /* x divided by y */ inline double APEX_DIVIDEDD (double X, double Y) { if (X == Y) z = 1.0d; else z = X/Y; return(z); } #define ddivBDD(XV,YV) (APEX_DIVIDEDD(XV,YV)) #define ddivIDD(XV,YV) (APEX_DIVIDEDD(XV,YV)) #define ddivDDD(XV,YV) (APEX_DIVIDEDD(XV,YV)) /* x min y */ inline int APEX_MINII (int x, int y) { if (x <= y) z = x; else z = y; return (z); } inline char APEX_MINCC (char x, char y) { if (x <= y) z = x; else z = y; return (z); } inline double APEX_MINDD (double x, double y) { if (x <= y) z = x; else z = y; return (z); } #define dminBBB(XV,YV) (XV&YV) #define dminIII(XV,YV) (APEX_MINII(XV,YV)) #define dminDDD(XV,YV) (APEX_MINDD(XV,YV)) #define dminCCC(XV,YV) (APEX_MINCC(XV,YV)) #define dminBII(XV,YV) (APEX_MINII(toi(XV),YV)) #define dminIBI(XV,YV) (APEX_MINII(XV,toi(YV))) #define dminBDD(XV,YV) (APEX_MINDD(tod(XV),YV)) #define dminDBD(XV,YV) (APEX_MINDD(XV,tod(YV))) #define dminIDD(XV,YV) (APEX_MINDD(tod(XV),YV)) #define dminDID(XV,YV) (APEX_MINDD(XV,tod(YV))) /* NB. max and min extended to characters */ inline int APEX_MAXII (int x, int y) { if (x >= y) z = x; else z = y; return (z); } inline char APEX_MAXCC (char x, char y) { if (x >= y) z = x; else z = y; return (z); } inline double APEX_MAXDD (double x, double y) { if (x >= y) z = x; else z = y; return (z); } /* x max y */ #define dmaxBBB(XV,YV) (XV|YV) #define dmaxIII(XV,YV) (APEX_MAXII(XV,YV)) #define dmaxDDD(XV,YV) (APEX_MAXDD(XV,YV)) #define dmaxCCC(XV,YV) (APEX_MAXCC(XV,YV)) #define dmaxBII(XV,YV) (APEX_MAXII(toi(XV),YV)) #define dmaxIBI(XV,YV) (APEX_MAXII(XV,toi(YV))) #define dmaxBDD(XV,YV) (APEX_MAXDD(tod(XV),YV)) #define dmaxDBD(XV,YV) (APEX_MAXDD(XV,tod(YV))) #define dmaxIDD(XV,YV) (APEX_MAXDD(tod(XV),YV)) #define dmaxDID(XV,YV) (APEX_MAXDD(XV,tod(YV))) /* x mod y */ #define dmodBBB(XV,YV,QUADct) ((~XV)&YV) #define dmodIII(XV,YV,QUADct) (Dmodulo(XV,YV)) #define dmodDDD(XV,YV,QUADct) (Dmodulo(XV,YV)) /* x star y */ #define dstarBBB(XV,YV) (XV|~YV) #define dstarIDD(XV,YV) (exp(XV,YV)) #define dstarDDD(XV,YV) (exp(XV,YV)) /* The dstari fragment will not work in integer type because EmitDyadicScalarFns % (and everyone else!) uses lhtype,rhtype to compute fragment % type. This fails for general star because we do not know that % the result type is going to be double_real, as we can not % ascertain that the right argument is positive. % Do it the slow way for now... 1995-11-18 % Actually, now that we have predicates, we can do better! 1996-04-30 */ #define dlogBDD(XV,YV) (log(YV)/log(XV)) #define dlogIDD(XV,YV) (log(YV)/log(XV)) #define dlogDDD(XV,YV) (log(YV)/log(XV)) /* NB. Extension of ISO APL to allow comparison of characters */ /* relationals */ #define dltBBB(XV,YV,QUADct) ((~XV)&YV) #define dltIBB(XV,YV,QUADct) (XVYV) #define dgtDDB(XV,YV,QUADct) (fixmeXV>YV) #define dgtCCB(XV,YV,QUADct) (XV>YV) #define dgeBBB(XV,YV,QUADct) (XV|~YV) #define dgeIIB(XV,YV,QUADct) (XV>=YV) #define dgeDDB(XV,YV,QUADct) (fixmeXV>=YV) #define dgeCCB(XV,YV,QUADct) (XV>=YV) /* As of 2004-09-16, we don't support lcm/gcd. Needs work in code generator and dfa to support side effects in scan, etc. rbe */ #define dandBBB(XV,YV) (XV&YV) /* Euclids algorithm for lcm */ #define dandII(XV,YV) (for initial ax := abs(XV); ay := abs(YV); \ u = min(ax,ay); v := max (ax,ay); \ while (v ~= 0) repeat \ v := mod(old u,old v); \ u := old v; \ returns value of (ax*ay)/u \ end for) /* Euclids algorithm for lcm */ #define dandDD(XV,YV) (for initial ax := abs(XV); ay := abs(YV); \ u = min(ax,ay); v := max (ax,ay); \ while (v ~= 0) repeat \ v := mod(old u,old v); \ u := old v; \ returns value of (ax*ay)/u \ end for) #define dorBBB(XV,YV) (XV||YV) /* Euclids algorithm for gcd */ #define dorII(XV,YV) (for initial \ ax := abs(XV); ay := abs(YV); \ u = min(ax,ay); v := max (ax,ay); \ while (v ~= 0) repeat \ v := mod(old u,old v); \ u := old v; \ returns value of u \ end for) /* Euclids algorithm for gcd */ #define dorDDD(XV,YV) (for initial \ ax := abs(XV); ay := abs(YV); \ u = min(ax,ay); v := max (ax,ay); \ while (v ~= 0) repeat \ v := mod(old u,old v); \ u := old v; \ returns value of u \ end for) #define dnandBBB(XV,YV) (~XV&YV) #define dnorBBB(XV,YV) (~XV|YV) #define dcircDDD(XV,YV) (if (XV = 1.0d) then sin(YV) \ elseif (XV = 2.0d) then cos(YV) \ elseif (XV = 3.0d) then tan(YV) \ elseif (XV = 4.0d) then exp((1.0d+YV*YV),0.5d) \ else error[double_real] end if) /* domain error check above */ /* 1 circle */ #define dcirc1DDD(XV,YV) (sin(YV)) /* 2 circle */ #define dcirc2DDD(XV,YV) (cos(YV)) /* 3 circle */ #define dcirc3DDD(XV,YV) (tan(YV)) /* 3 circle */ #define dcirc4DDD(XV,YV) (exp((1.0d+YV*YV),0.5d)) #define toB(x) tob((x)) #define toI(x) toi((x)) #define toD(x) tod((x)) #define toC(x) toc((x)) #if 0 /* sac vs APL rules on Boolean to integer */ inline int toi(bool b) { if (b) z = 1; else z = 0; return (z); } inline int toi(double b) { if (0.0d == b) z = 1; else z = 0; return (z); } inline double tod(bool b) { if (b) z = 1.0d; else z = 0.0d; return (z); } #endif /* Compiled by APEX at 2004-10-22 17:14:06.000 */ inline double[+] plusDIDsx(double x, int[+] y ) { /* SxA scalar function */ xel = toD(x); z = with( . <= iv <= .) { yel = toD(_sel_(iv,y)); } genarray( _shape_(y), dplusDID(xel,yel)); return(z); } inline double barDIDsl(double x, int y ) { /* SxS dyadic scalar fn, shapes match */ z = dbarDID(toD(x),toD(y)); return(z); } /* Index generator */ inline int[.] iotaXII(int shp, int QUADio) { /* HELP! Needs domain check for negative shp */ res = with( . <= [i] <= .) genarray( [toi(shp)], i+QUADio); return( res); } inline int[.] iotaXIIsy(int y, int QUADio) { return(iotaXII(y, QUADio)); } /* Index generator when argument known to be legal */ inline int[.] iotaXIINonNegsy( int shp, int QUADio) { res = with( . <= [i] <= .) genarray( [toi(shp)], i+QUADio); return( res); } /* Index generator on 1-element vectors */ inline int[.] iotaXII(int[1] shp, int QUADio) { /* HELP! Needs length error check */ /* HELP! Needs domain check for negative shp */ res = with( . <= [i] <= .) genarray( [toi(shp[0])], i+QUADio); return( res); } double quadXDD(double y, int QUADpp, int QUADpw) { /* {quad}{<-} scalar */ return(y); } double quadXDDsy(double y, int QUADpp, int QUADpw) { /* {quad}{<-} scalar */ return(y); } double quadXDD(double[*] y, int QUADpp, int QUADpw) { /* {quad}{<-} non-scalar */ return(y); } double quadXDDsy(double[*] y, int QUADpp, int QUADpw) { /* {quad}{<-} non-scalar */ return(y); } inline double plusslx10(double[.] y) { z = with (_mul_SxA_(0,_shape_(y)) <= iv < _shape_(y)) fold( +, 0.0d, tod(_sel_(iv, y))); return(z); } /* Start of function prd */ double prd(int y,int QUADio) { TMP_23=iotaXII( y ,QUADio) ; TMP_24=plusDIDsx( 0.0e0 ,TMP_23 ); r_0=plusslx10( TMP_24 ) ; r=r_0; return(r_0); } /* End of function prd */ /* Start of function main */ int main() { QUADio_0=toi(( false ) ); QUADct_0=( 1.0e-13 ) ; QUADpp_0=( 10 ) ; QUADpw_0=( 80 ) ; QUADrl_0=( 16807 ) ; QUADio_1=toi(( false ) ); QUADpp_1=( 10 ) ; QUADpw_1=( 10 ) ; QUADct_1=( 1.0e-13 ); n_0=( 5000000 ) ; QUADrl_1=( 16807 ) ; r_0=prd( n_0 ,QUADio_1) ; #if 0 TMP_68=quadXDD( r_0 ,QUADpp_1,QUADpw_1) ; r_1=( false ) ; r=r_1; #endif return(toi(r_0)); } /* End of function main */