× 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.



First, thanks for helping me understand this. After doing all this with
zoned and packed data types for a couple decades, when things get slow,
I start to branch out into the vast unknown to try to see what else
works (and what I need to know to make it work).

When I reported that "NegativeValue = %int(PositiveValue) - 21;" didn't
work, I messed up. I had actually coded
"NegativeValue = %int(PositiveValue - 21);", and as I now understand,
the subtraction took place before the type conversion, and did indeed
cause wheels to fall off. Please accept my apologies for my sloppiness
causing the extra efforts.

I truly appreciate the wisdom shared here. One of the tough things about
our business is that we often work in small shops where local expertise
is lacking. Resources such as this list are invaluable for extending my
capabilities into the "vast unknown".

With great respect and gratitude to all who set me straight,
Michael Koester
~~~~~~~~~~~~~~~~~~~~~~

-----Original Message-----
From: rpg400-l-bounces@xxxxxxxxxxxx
[mailto:rpg400-l-bounces@xxxxxxxxxxxx] On Behalf Of Scott Klement
Sent: Monday, September 27, 2010 6:25 PM
To: RPG programming on the IBM i / System i
Subject: Re: definintion of signed integer?

Hi Michael,

I found that the unsigned PositiveValue was indeed causing issues.
Changing PositiveValue to 3i 0 (option 1)

That'd work, as long as you didn't need PositiveValue to store numbers
up to 255.

Alleviated the problem. Leaving PositiveValue at 3u 0 and using the
assignment " NegativeValue = %int(PositiveValue) - 21;" (2a)

Alright... this comment surprised me. So I tried it, I took your
example (which had several syntax errors in it) and fixed it up and
tried it... and it works just fine for me. No errors! Here's the code
I was running, copy/pasted verbatim:

D PositiveValue s 3u 0
D NegativeValue s 3i 0
/free
PositiveValue = 3;
NegativeValue = %int(PositiveValue) - 21;
*inlr = *on;
/end-free

Are you saying that on your box, this code crashes/halts?! It doesn't
for me. And it shouldn't, based on my understanding of intermediate
results.

The original issue is that you had nothing on the right-hand side to
make the intermediate result a signed result. You had this:

NegativeValue = PositiveValue - 21;
...which is....
NegativeValue = (Unsigned Int) - 21.

Since there's nothing to indicate a signed result on the right-hand side

of the equation, the intermediate result should be unsigned -- so it
crashes. That makes perfect sense.

Likewise, if you did this (as suggested by Alan):

NegativeValue = %int(PositiveValue - 21);

This actually doesn't change anything, and should report the same error,

because the phrase 'PositiveValue - 21' is STILL unsigned, and therefore

can't go negative. Granted, that unsigned value is now going to be
converted to a signed one -- but that won't happen until AFTER the
subtraction, and therefore it'll still fail. (And actually, the
original example also converted it to signed after the subtraction,
since the result field was signed, so... you've accomplished nothing by

wrapping the whole thing in an %int()!)

However, you just told me that this won't work:

NegativeValue = %int(PositiveValue) - 21;

That's a whole different story, since the unsigned field is converted to

signed BEFORE the subtraction takes place, and therefore has a signed
intermediate result. This _should_ work. And it does in my tests. But

you just posted that it doesn't??!


(You'd think a business language should be a bit more forgiving in
basic math functionality, but my expectations are often unrealistic)

It is... RPG's native numeric data types of packed and zoned both take
care of this for you, so you can't screw it up. This is only a problem
with the (rather unusual) unsigned data type that was, frankly, added
primarily for compatibility with other languages. Thus, RPG as a
business language _is_ more forgiving. What's not is the other
languages that the U data type was intended to achieve compatibility
with.

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.