Colin Brace wrote:
>
> Hello,
>
> What is the equivalent of the MOD function (in BASIC et al) in REXX? I
> seem to recall knowing it at one time but now can't find it anywhere...
>
> TIA.
>
> --
> Colin Brace
> Amsterdam
> http://www.lim.nl
Hi! Colin,
You might find the enclosed useful. Use some discression, since
the numeric size and ram size will limit you. Also rexx is slow
with digit lengths greater than 10,000 digits. Os/2 also has a
numeric digits maximaum of 1e7, Pcdos7 rexx has a limit of 2**15-1 for
numeric digits.
You may invoke the routine via Rexxtry and as a function.
like:
>>rexxtry> x=mod(12345,37,100)
> say x
Now you can see it working......
Have fun.
Russ
Any other's on this rexx forum that have questions please contact me via
Rjm...@Attglobal.net
If you need a reference then consult:
Concrete Mateematics
By Gram, Knuth,Patashnic
Pgs 81-86
/*INVOKE MOD(X,Y,NUM_DIG)*/;MOD:;/*PROCEDURE EXPOSE*/;LBL='>MOD, '
IF ARG(2)=0 THEN;EXIT LBL;IF DATATYPE(ARG(1))='CHAR' THEN EXIT
LBL||ARG(1)
/*NUMERIC DIGITS NUM_DIG 3RD ARG*/;ND=LENGTH(1/3)-2;DE=LENGTH(ARG(1))
SE=LENGTH(ARG(2));IF
DATATYPE(ARG(3))="NUM"&ARG(1)\=''&DATATYPE(ARG(1))=,
"NUM"&DATATYPE(ARG(2))="NUM" THEN;NUM_MAX=MAX(ARG(3),ND,DE,SE);ELSE;DO
IF ARG(1)\=""&DATATYPE(ARG(1))="NUM"&DATATYPE(ARG(2))="NUM" THEN
NUM_MAX=MAX(ND,DE,SE);ELSE;EXIT LBL;END;DROP ND DE SE;NUM_MAX=NUM_MAX,
+NUM_MAX%10+2;NUMERIC DIGITS NUM_MAX;X=FORMAT(ARG(1),,,,0);/*3
ARGUMENTS*/
IF ARG(2)\=0 THEN;DO;ANS=ARG(1)-ARG(2)*(ARG(1)%ARG(2));END;ELSE
ANS=ARG(1);ANS=FORMAT(ANS,,,,0);RETURN ANS
/*13 Jul 1987 12:23:16 PROPERTY OF R.MATHESON.COPYRIGHTED*/
/*17 Dec 1997 11:07:08 PROPERTY OF R.MATHESON.COPYRIGHTED*/
Well, they do say that you can write a FORTRAN program in any language...
>-=-=-=-=-=-
>[Attachment type=text/x-vcard, name=rjmrjm.vcf]
>-=-=-=-=-=-
Please don't do that... thanks.
--
---- Ian Collier : i...@comlab.ox.ac.uk : WWW page (including REXX section):
------ http://users.comlab.ox.ac.uk/ian.collier/imc.shtml
New to this group? Answers to frequently-asked questions can be had from
http://rexx.hursley.ibm.com/rexx/ .
I don't understand why one would want to obfuscate a REXX program this
badly --- I was going to show
my version of it, but when I had more improvements than the # of source
lines, I figured, why
bother? Unless this is some kind of test to see if we REXX programmers
have a sense of humor.
IF xxxx THEN DO; statement; END; ??? ND=digits()-2 ???
How about an ARG or PARSE statement to eliminate all those ARG(n)
function calls?
Checking for (valid) numeric arguments up front? yada yada yada.
Oh well, one man's treasure, another man's ...
Gerard S.
> > What is the equivalent of the MOD function (in BASIC et al) in > >
> > REXX?
Let me note
D.E.Knuth writes in his The Art of Computer Programming, Vol. 1:
If X and Y are any real numbers, we define the following operation:
MOD(X, Y) = X - Y * FLOOR(X/Y) if Y <> 0;
MOD(X, 0) = X
The following program displays on the screen the results of Knuth's
excercises 8, 9, 10 in the chapter 1.2.4:
say MOD(100, 3) MOD(100, 7) MOD(-100, 7) MOD(-100, 0)
/* displays 1 2 5 -100 */
say MOD(5, -3) MOD(18, -3) MOD(-2, -3)
/* displays -1 0 -2 */
say MOD(1.1, 1) MOD(0.11, 0.1) MOD(0.11, -0.1)
/* displays 0.1 0.01 -0.09 */
exit
MOD: procedure
parse arg X, Y
if Y = 0 then return X
return X - Y * FLOOR(X/Y)
FLOOR: procedure /* Author Gerard Schildberger */
parse arg F
return TRUNC(F) - (F < 0) * (F <> TRUNC(F))
Vladimir Zabrodsky
http://www.geocities.com/zabrodskyvlada/rexxpage.html
with Album of Algorithms and Techniques for Standard Rexx
Sent via Deja.com http://www.deja.com/
Before you buy.
Hi,
MOD is done with //
x = y // 2
x contains the remainder when y is divided by 2 (zero if y is exactly
divisable by 2)
ok?
> /*INVOKE MOD(X,Y,NUM_DIG)*/;MOD:;/*PROCEDURE EXPOSE*/;LBL='>MOD, '
> IF ARG(2)=0 THEN;EXIT LBL;IF DATATYPE(ARG(1))='CHAR' THEN EXIT
> LBL||ARG(1)
> /*NUMERIC DIGITS NUM_DIG 3RD ARG*/;ND=LENGTH(1/3)-2;DE=LENGTH(ARG(1))
> SE=LENGTH(ARG(2));IF
> DATATYPE(ARG(3))="NUM"&ARG(1)\=''&DATATYPE(ARG(1))=,
> "NUM"&DATATYPE(ARG(2))="NUM" THEN;NUM_MAX=MAX(ARG(3),ND,DE,SE);ELSE;DO
> IF ARG(1)\=""&DATATYPE(ARG(1))="NUM"&DATATYPE(ARG(2))="NUM" THEN
> NUM_MAX=MAX(ND,DE,SE);ELSE;EXIT LBL;END;DROP ND DE SE;NUM_MAX=NUM_MAX,
> +NUM_MAX%10+2;NUMERIC DIGITS NUM_MAX;X=FORMAT(ARG(1),,,,0);/*3
> ARGUMENTS*/
> IF ARG(2)\=0 THEN;DO;ANS=ARG(1)-ARG(2)*(ARG(1)%ARG(2));END;ELSE
> ANS=ARG(1);ANS=FORMAT(ANS,,,,0);RETURN ANS
> /*13 Jul 1987 12:23:16 PROPERTY OF R.MATHESON.COPYRIGHTED*/
> /*17 Dec 1997 11:07:08 PROPERTY OF R.MATHESON.COPYRIGHTED*/
> --------------B365F153E44D0D1B605708F4
> Content-Type: text/x-vcard; charset=us-ascii;
> name="rjmrjm.vcf"
> Content-Transfer-Encoding: 7bit
> Content-Description: Card for R. J. Matheson
> Content-Disposition: attachment;
> filename="rjmrjm.vcf"
>
> begin:vcard
> n:Matheson;R. J.
> x-mozilla-html:FALSE
> adr:;;;;;;
> version:2.1
> email;internet:Rjm...@Attglobal.net
> x-mozilla-cpt:;-2016
> fn:Matheson, R. J.
> end:vcard
>
> --------------B365F153E44D0D1B605708F4--
Yes, the "//" operator of rexx will return the remainder but we are
speaking about the mathematical function modulo.
Consider the operation "x modulo 0" which is equal to x. This cannot be
done with the rexx operator //.
So.... look up the references.
Be carful what you put into hard copy. The reason why IBM and all
say that // is not modulo is the above as an example.
in rexx the case of zero is:
if x=0 then return x
Have a great day.
Russ
"R. J. Matheson" wrote:
>
> Hi! Bob,
>
> Yes, the "//" operator of rexx will return the remainder but we are
> speaking about the mathematical function modulo.
>
> Consider the operation "x modulo 0" which is equal to x. This cannot be
> done with the rexx operator //.
>
> So.... look up the references.
> Be careful what you put into hard copy. The reason why IBM and all
> say that // is not modulo is the above as an example.
>
> in rexx the case of zero is:
after setting numeric digits .....
> if y=0 then; return x ;else;return x//y