× 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: Overflow errors on add
  • From: Hans Boldt <boldt@xxxxxxxxxx>
  • Date: Thu, 24 Sep 1998 09:04:01 -0400

Eric wrote:
>     There is a command line option TRUNCNBR in the CRTBNDRPG command.
>     This will cause overflow values to be truncated. This doesn't work
>     on calculations performed within expressions (eval and other
>     opcodes that us the extended factor 2 field). In cases where you
>     know you'll have an overflow occur, just go back to the standard
>     math ops in place of the expression calcs.

Also, TRUNCNBR does not apply to any of the non-decimal
numeric datatype: integer, unsigned, and float.  TRUNCNBR
applies only to the decimal datatypes (packed, zoned, and
binary) and only on the old-style fixed format opcodes.

Considering the risks involved with TRUNCNBR(*YES),
perhaps programmers should use conversion to RPG IV as an
opportunity to redo their numeric operations that rely on
truncation.  Since very few calculations really need to
take advantage of truncation, running with TRUNCNBR(*NO)
can help you ensure that your calculations produce
correct results.  For the very few cases where truncation
is needed, there are alternatives, such as MVR or even
MOVE.

One place where truncation is sometimes justified is to
compute the remainder after division by some multiple of
10 in order to compute a hash index.  While this is
certainly easy, it is a very poor way to implement a hash
table.  Hash tables work best when the hash table size is
a prime number.

My bottom line recommendation is this:  Run your RPG
programs with TRUNCNBR(*NO).  If you get the numeric
overflow exception, determine why.  If it's a bug, fix it.
If not, recode the computation and use MOVE or MVR to
perform the truncation.

Cheers!  Hans

Hans Boldt, ILE RPG Development, IBM Toronto Lab, boldt@ca.ibm.com
+---
| This is the Midrange System Mailing List!
| To submit a new message, send your mail to MIDRANGE-L@midrange.com.
| To subscribe to this list send email to MIDRANGE-L-SUB@midrange.com.
| To unsubscribe from this list send email to MIDRANGE-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 ...


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.