On 2025-08-26 02:56, Paul Gilmartin wrote:
On 8/25/25 09:48, Robin Vowels wrote:
    ...>

Divsion by 10 is interesting, gives the exact answer:
j = k + 1
m = j +2j
n = m + m/16
p = n + n/256
q = p/32

No division here; these are logical shifts.

More details in my paper, "Division by 10", of 1992.
    ...
Where is this available?

Australian Computer Journal v 24, no 3, 1992.

 How does the performance
compare?  Is suspect it wins on a minicomputer
lacking hardware divide.

What are the limits of the domain of k?  does it
overflow for large values?  (Note the nearby
thread on Documentation.)

That version is for positive integer <= 32768.
Other versions are for 32-bit and 8-bit integers,
and for signed and unsigned.

If the processor has an extension word or halfword,
there's no overflow.  Where such an extension is not available,
an alternative algorithm is given.

The following shows failures for negative k.  But
it might depend on the convention of integer divide.
/* Rexx */
trace N
signal on novalue

do K =-1000 to 1000 by 29
    j = k + 1
    m = j +2*j
    n = m + m%16
    p = n + n%256
    q = p%32
    say k q
    if q<>k%10 then say '*** Oops! ***'
    end k

Reply via email to