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.

This thread ...

Follow-Ups:
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.