/* ------------------------------- */ /* +++ STANDARD HEADER +++ */ /* The RPG Developer Network */ /* http://www.RPGIV.com */ /* (c) Robert Cozzi, Jr. */ /* All rights reserved. */ /* No warranty is expressed or */ /* implied, and none is given. */ /* ------------------------------- */ ** Illustrates a basic math problem created when moving to EVAL ** the new RPG IV EVAL operation code. Some utilities provide ** a way to convert RPG IV code from fixed-format to EVALS. ** This example program illustrates the EVAL math bug. ** ** The math problem being solved by this program is as ** follows: ** ** (32.78 / 15) * 100 ** ** In RPG III and RPG IV the result is either: ** 218.00 or 219.00 depending on how Half Adjust usage. ** ** In RPG IV, with EVAL, there is no directly correlation. ** With EVAL the result is _always_ 218.53 ** ** Try it! Upload, compile, and run this program. ** It outputs the results of the routines to a print file. ** If you are on V3R2 or V3R6 you will not be able to ** compile the program as it uses %EDITC and two ** operation extenders that are not supported in ** those releases. ** ** Posted on the Internet at www.RPGIV.com ** .....F*ileName++IFEASFRlen+LKeylnKFDevice+.Functions++++++++++++++++++++++++++++ 0010 FQPrint O F 132 PRINTER oflind(*INOF) .....D*ame+++++++++++EUDS.......Length+TDc.Functions++++++++++++++++++++++++++++ 0020 D Count S 7p 0 Inz(15) 0030 D szOut S 64A 0040 D Sum S 7p 2 Inz(32.78) 0050 D Temp S 7p 2 0060 D TempH S 7p 2 0070 D FixedA S 7p 2 0080 D FixedB S 7p 2 0090 D FixedC S 7p 2 0100 D FixedD S 7p 2 0110 D FixedE S 7p 2 0120 D FixedF S 7p 2 0130 D FreeA S 7p 2 0140 D FreeB S 7p 2 0150 D FreeC S 7p 2 0160 D FreeD S 7p 2 0170 D FreeE S 7p 2 0180 D FreeF S 7p 2 .....C*Rn01Factor1+++++++OpCode(ex)Factor2+++++++Result++++++++Len++DcHiLoEq.... 0190 C Sum Div(h) Count FixedA 0200 C Mult 100 FixedA 0210 C eval szOut= 'lDiv(h) Mult=' + %EditC(FixedA :'J') 0220 C EXCEPT Output 0230 C Sum Div Count FixedB 0240 C Mult 100 FixedB 0250 C eval szOut= 'lDiv Mult =' + %EditC(FixedB :'J') 0260 C EXCEPT Output 0270 C Sum Div Count Temp 0280 C Temp Mult 100 FixedC 0290 C eval szOut= 'lDiv lMult =' + %EditC(FixedC :'J') 0300 C EXCEPT Output 0310 C Sum Div(H) Count TempH 0320 C TempH Mult(H) 100 FixedC 0330 C eval szOut= 'lDiv(h)lMul(H)='+ %EditC(FixedC :'J') 0340 C EXCEPT Output 0350 C Sum Div(H) Count TempH 0360 C TempH Mult 100 FixedD 0370 C eval szOut= 'lDiv(h) lMult ='+ %EditC(FixedD :'J') 0380 C EXCEPT Output 0390 C Sum Div Count Temp 0400 C Temp Mult(H) 100 FixedE 0410 C eval szOut= 'lDiv lMult(H) ='+ %EditC(FixedD :'J') 0420 C EXCEPT Output .....C*Rn01..............OpCode(ex)Extended-factor2+++++++++++++++++++++++++++++ 0430 C Eval FreeA = sum / count * 100 0440 C eval szOut= 'Eval sum/count='+ %EditC(FreeA :'J') 0450 C EXCEPT Output 0460 C Eval(h) FreeB = sum / count * 100 0470 C eval szOut='Eval(h) sum/count='+%EditC(FreeB :'J') 0480 C EXCEPT Output 0490 C Eval(R) FreeC = sum / count * 100 0500 C eval szOut='Eval(R)sum/count='+%EditC(FreeC :'J') 0510 C EXCEPT Output 0520 C Eval(hR) FreeD = sum / count * 100 0530 C eval szOut='Eval(HR) sum/cnt='+%EditC(FreeD :'J') 0540 C EXCEPT Output 0550 C Eval(m) FreeE = sum / count * 100 0560 C eval szOut='Eval(m)sum/count='+%EditC(FreeE :'J') 0570 C EXCEPT Output 0580 C Eval(hm) FreeF = sum / count * 100 0590 C eval szOut='Eval(hm)sum/cnt ='+%EditC(FreeF :'J') 0600 C EXCEPT Output 0610 C Eval *INLR = *ON .....O*ormat++++DAddn01n02n03Except++++SpbSpaSkbSka............................. 0620 OQPrint E OUTPUT 1 .....O*.............n01n02n03Field+++++++++YB?End++PConstant/Editword+++++++++++ 0630 O szOUT B +002