× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.


  • Subject: Re: Re[2]: Exponential
  • From: Douglas Handy <dhandy1@xxxxxxxxxxxxx>
  • Date: Tue, 08 Aug 2000 10:44:06 -0400

Patrick,

>it bothers me that 10**0 doesn't equal one in a
>nested expression.

Such is the nature of floating point.  It equaled 0.9999999... which
is why Ken suggested using %dech() to immediately round the nested
expression intermediate value.

>As a rule of thumb should I half round all eval statements?

As a rule of thumb, I try to avoid floating-point when practical,
especially with monetary values.  Then, when I do use floating-point,
I use half-adjust to help compensate for floating-point's inherent
inability to represent some numbers exactly.

As another rule of thumb, instead of just putting the half adjust on
the entire eval statement, I'd attempt deal with it immediately and
get the intermediate result back into a packed decimal format.

This can be done by using an extra EVAL(H) with just the
floating-ponit expression and a packed decimal result, or by judicious
use of %dech() such as in Ken's example.  But as Ken's example points
out, you need to understand the limits of your data such as only using
a positive exponent, etc.

In most cases, just using eval(h) may produce the same results.  But I
prefer to do the rounding at the intermediate result level with
floating-point, to avoid any potential of propagating and magnifying
the small discrepency in complex expressions.  Remember, if any
operand in an expression is floating-point, the operations are done in
floating point.  By using %dech() or a separate eval(h), the rest of
the expression will have only decimal operands and therefore can use
decimal arithmetic instead of floating-point.

Doug
+---
| 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 thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

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.