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.