Hello
Because I am new to RPGIV (existing using RPGIII) . Recently I need to write a sub-program using RPGIV (or RPGILE ? ).
This sub-program will receive two parmerter (X , Y) and output one parmeter (Z) (which are in numeric format - BTW what is the
max precision for numeric format in RPGIV / RPGILE? (i.e. max no of decimal points supported) )
The value of Y can be a negative number or number in value between 0 and 1 (ie. Y is a fraction number of 1/n) or number of value > 1)
The function of this sub-pgm is to calculate X to the power of Y and then return Z.
I have this in mind - > 4 cases:
(1) If Y < 0 (ie. -Y) , then Z = 1/ X to the power of +Y)
(2) If Y = 0 , then Z = 0
(3) If Y between 0 and 1 (a fraction of 1/n) , then Z= X to the power of n (with decimal digit)
(4) If Y > 1, then Z = X to the power of n
Examples as below:
if X=9 and n=2 then X**n = 81 (i.e 9**2)
if x=9 and n=0.5 (i.e. 1/2) then X**n =3 (i.e. square root)
Can anyone give some idea to me : How to implement this login in RPGIV (if possible, can it be show in source code ?)
Beside , Can this sub-program written in RPGIV / RPGILE be called by a traditional RPGIII program ?
Many many thanks
You can send directly to my mail box : veronica_lui@mlchk.com
Software/Hardware used:
ASKED:
April 22, 2005 1:39 AM
UPDATED:
April 23, 2005 8:31 PM
Why do you need a sub program, as you can code EVAL Z=X**Y
directly in your program?
You should consider defining the result as a floating point field which allows +ve and -ve numbers 10 power-308 thru 10 power 308 with 16 significant digits if your potentail results are not within the range of a fixed packed decimal format
Hi Dgrove,
I would guess because she isn’t doing a straight forward “raise to the power of” calculation. The original question stated four rules:
I have this in mind – > 4 cases:
(1) If Y 1, then Z = X to the power of n
which involves a couple of extra lines for conditions, etc.
All the best
Jonathan