Hmmm.... I think you are correct - Sorry!
In this situation we know the data will never be negative but I agree with
your point.
Yes *HIVAL is what we would use - just used the 999999999's for the
example.
The amount of data is also small so Mult of Sub is not of concern.
Appreciate all the answers
Cheers
From: "John Yeung" <gallium.arsenide@xxxxxxxxx>
To: "Midrange Systems Technical Discussion"
<midrange-l@xxxxxxxxxxxxxxxxxx>
Date: 13/02/2020 07:29 AM
Subject: Re: Sorting an array ascending and descending
Sent by: "MIDRANGE-L" <midrange-l-bounces@xxxxxxxxxxxxxxxxxx>
On Wed, Feb 12, 2020 at 3:51 PM Don Brown via MIDRANGE-L
<midrange-l@xxxxxxxxxxxxxxxxxx> wrote:
Yes we have used that method of 9's compliment previously.
Hmm... this is MIDRANGE-L, not RPG400-L, though this seems like an RPG
question.
RPG has some conveniences for this approach, like *HIVAL (so you don't
have to count out the nines yourself, especially handy if the fields
ever change size). Personally, I still prefer multiplying by -1
instead. Feels a bit more "mathy" and less "computery" (I like mathy).
Moreover, it works even if some of your values are negative. (*HIVAL
minus some negative number will overflow a same-sized field.) Finally,
if you just take the negative, you can make the mental conversion
quicker if you need to visually inspect values.
I don't know if it would be a performance optimization to subtract
from 0, rather than multiply by -1. I know when I first started out in
RPG, the Z-SUB opcode felt to me as though it *ought* to be faster
than MULT (I never tested this; it just *looked* like it must be
related to a hardware-supported instruction, on top of
addition/subtraction generally being faster than multiplication.)
John Y.
As an Amazon Associate we earn from qualifying purchases.