Jump to content

Talk:Integer long division

From Rosetta Code

task wording clarification

It should be noted that most of the task's preamble is actually referring to integers   (not numbers)   expressed in base ten,   but particularly,   the 4th paragraph.   Also, nothing was mentioned or inferred about signed integers (allowed or not?, or just ignored?).

>> Yes, the title of the task is Integer long division. I did not consider signed integers, thanks for pointing it out. Simply consider positive unsigned integers.

In the "note"   (2nd sentence, 4th paragraph),   I was rather uncertain in this period of time as to the meaning of the word   period     (... will always produce a period.

Did you mean in the context of a period   (a group of repeated decimal digits),   or a   decimal point,   (also known as)   a period.

>> A language ambiguity. Here I mean a repeating sequence of digits.

Furthermore,   most of the 4th paragraph isn't true because   ... the division of any two numbers ...     is incorrect,   it probably should say   ... the division of any two integers ....

Numbers   could produce vulgar (or improper) (decimal) fractions.     -- Gerard Schildberger (talk) 19:28, 15 September 2021 (UTC)

>> My bad. I meant to say integers, thanks for spotting it.


Also, not all computer programming languages produce a decimal point when doing (perfect/complete) division of two integers.

8   divided by   4   is   2   (no decimal point)   when performed by a REXX program.   There can be similar results in other computer programming languages that make use of "picture" (PIC) specifications (and other such animals)   such as in the COBOL and PL/I languages.     -- Gerard Schildberger (talk) 19:28, 15 September 2021 (UTC)


Finally, there is/are the case(s) of     / 7     where the period is zero.     -- Gerard Schildberger (talk) 19:28, 15 September 2021 (UTC)

No need to remember all remainders

Many examples use an array/list/dictionary of "seen" values. This is not necessary when you want to output the complete period.
One has only to remind the first value of the nominator in base, where Base^k gets greater than the Denominator and find the repetition of that value.
Wiki:Algorithm_for_positive_bases

It looks as if the code listed above also uses a hash, called occurs[p], which is used to monitor if a value p has been seen already or not. p is explained to be various values that change but are 0 ≤ (previous p) < q according to that code. I expect all such hashings may work, and you may want to benchmark which hash method is faster to tell which should be used. --Wherrera (talk) 23:07, 5 January 2025 (UTC)
Cookies help us deliver our services. By using our services, you agree to our use of cookies.