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 1991.
...
Where is this available? 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.)
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
--
gil