Post Reply 
(42, all flavours) Integer Division - how?
12-17-2020, 10:03 PM (This post was last modified: 12-17-2020 10:29 PM by Albert Chan.)
Post: #38
RE: (42, all flavours) Integer Division - how?
(12-17-2020 06:41 PM)Albert Chan Wrote:  If Cc00/Xx fractional part is 0.5, it implied Cc000 / Xx is integer, ends in 5.

To "remove" 3 0's, and turn last digit to 5, Xx = 8*k
(Cc00 ± 100) / Xx will *not* be half-way case, since 100/8 = 12.5, not an integer.

We can use gap test to check for half-way case. This work on a 2-digits calculator:

→ if (Cc00+100)/Xx - Qq < Qq - (Cc00-100)/Xx then Qq := Qq - 1;

(12-17-2020 07:50 PM)Werner Wrote:  No.. each 0 is the length of a half integer, so for a 12 digit machine it is 000000 and for Free42/DM42 it's 17 zeroes ;-)

I misunderstood. "0" = h zeroes, not 1 zero (*)
But, the logic holds. Just replace "hidden" 1 with h

\(\large{CcOO \over Xx}\) is half-way cases → \(Xx = 2^{2h+1} \cdot k\)

\(\large{CcOO\;±\;IOO \over Xx}\) will *not* be half-way case, since \(
\large{10^{2h} \over 2^{2h+1}} = {5^{2h} \over 2}\), not an integer.

Gap test work with with "half-integers" too.

(*) I had assumed "0" = 1 zero, on a 2-digit calculator, and checked how the code perform.
Code:
Cases      %   Types
  404     8.2  FRAC(Qq) > 0, return Qq
 2420    48.9  Mod test, return Qq
 2050    41.4  Mod test, return Qq - 1
   76     1.5  Half-way cases (evenly split 38/38)
-------------
 4950     100
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: (42, all flavours) Integer Division - how? - Albert Chan - 12-17-2020 10:03 PM



User(s) browsing this thread: 1 Guest(s)