|
Well I get the correct answer for the calculation.I am running it on V4R4.May be it could be in earlier releases.
Rizwan Ahamed
Analyst/Programmer
Corporate ITD
The National Shipping Company of Saudi Arabia
Tel - 4785454 X 611, Fax - 4778036, P.O. Box 8931, Riyadh 11492, KSA [ rizwan@nscsa.com.sa]
-----Original Message-----
From: bmorris@ca.ibm.com [SMTP:bmorris@ca.ibm.com]
Sent: Tuesday, August 08, 2000 8:11 PM
To: RPG400-L@midrange.com
Subject: Re: Exponential
>Date: Mon, 7 Aug 2000 13:31:23 -0400
>From: Contractor1@Parkdalemills.com
> ...
>D#ExPo S 1P 0 Inz(0)
>D#Base S 4P 2 Inz(18.10)
>D#Result S 5P 2
>
>The Eval statement:
>Eval #Result = #Base + (1 / (10 ** #Expo))
>
> Expected answer: 19.10
> Actual answer: 19.09
> ...
Patrick,
Others have already suggested that you use (R) and (H), both
good suggestions, especially when division and floating point
are being used in an expression. But even when resdecpos and
half-adjust are both active, using floating point can introduce
errors into your program. This is because floating point uses
a binary representation and some decimal values can't be expressed
exactly as binary numbers.
To limit the effects of the floating point to just the
exponentiation, try this, getting the result of (10 ** #Expo)
in a decimal(x,y) value (for x and y, use whatever you used
as the length and decimals for your #CalcExpo temporary):
#Base + (1 / %dech(10 ** #Expo : x : y))
I can't tell if this will always give the correct answer, but
it will give the same results as your 2-operation method using the
#CalcExpo temporary.
(To avoid floating point completely, you could do the exponentiation
in a loop, or you could handle it with a character overlay of a zoned
value, shifting the data #Expo places left or right.)
Barbara Morris
+---
| This is the RPG/400 Mailing List!
| To submit a new message, send your mail to RPG400-L@midrange.com.
| To subscribe to this list send email to RPG400-L-SUB@midrange.com.
| To unsubscribe from this list send email to RPG400-L-UNSUB@midrange.com.
| Questions should be directed to the list owner/operator: david@midrange.com
+---
As an Amazon Associate we earn from qualifying purchases.
This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].
Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.