Integer long division: Difference between revisions
m
syntax highlighting fixup automation
No edit summary |
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
||
Line 17:
=={{header|C++}}==
{{libheader|GMP}}
<
#include <iomanip>
Line 72:
std::cout << '\n';
}
}</
{{out}}
Line 91:
=={{header|Common Lisp}}==
<
(defun $/ (a b)
"Divide a/b with infinite precision printing each digit as it is calculated and return the period length"
Line 114:
() ))
</syntaxhighlight>
{{out}}
<pre>
Line 132:
partly because the Unicode "overline" might not display properly.
In case the overline style is preferred, simply use the following function in the obvious way:
<
def overline: explode | map(., 773) | implode;</
<
def idivide($j):
. as $i
Line 190:
"Period is \($r|length)\n" ;
task</
{{out}}
<pre>
Line 239:
=={{header|Julia}}==
<
dpart, remainders, r = "", Dict{BigInt, Int}(), BigInt(numr) % denr
while (r != 0) && !haskey(remainders, r)
Line 270:
testrepeatingdecimals()
</
<pre>
Line 289:
{{trans|Wren}}
{{libheader|bignum}}
<
import bignum
Line 344:
echo &"{a}/{b} = {repr}"
echo &"Cycle is <{cycle}>"
echo &"Period is {period}\n"</
{{out}}
Line 392:
=={{header|Perl}}==
<
use warnings;
use utf8;
Line 421:
printf "%10s Period is %5d : %s\n", $_, long_division split '/'
for <0/1 1/1 1/5 1/3 -1/3 1/7 -83/60 1/17 10/13 3227/555 1/149></
{{out}}
<pre> 0/1 Period is 0 : 0
Line 438:
=={{header|Phix}}==
Translation of the Python code linked to by the Wren entry, modified to cope with negatives.
<!--<
<span style="color: #008080;">with</span> <span style="color: #008080;">javascript_semantics</span>
<span style="color: #008080;">procedure</span> <span style="color: #000000;">test</span><span style="color: #0000FF;">(</span><span style="color: #004080;">sequence</span> <span style="color: #000000;">s</span><span style="color: #0000FF;">)</span>
Line 481:
<span style="color: #0000FF;">{</span><span style="color: #000000;">476837158203125</span><span style="color: #0000FF;">,</span><span style="color: #000000;">9223372036854775808</span><span style="color: #0000FF;">}}[</span><span style="color: #000000;">1</span><span style="color: #0000FF;">..$-(</span><span style="color: #7060A8;">machine_bits</span><span style="color: #0000FF;">()=</span><span style="color: #000000;">32</span><span style="color: #0000FF;">)]</span>
<span style="color: #7060A8;">papply</span><span style="color: #0000FF;">(</span><span style="color: #000000;">tests</span><span style="color: #0000FF;">,</span><span style="color: #000000;">test</span><span style="color: #0000FF;">)</span>
<!--</
{{out}}
The results below are on 64 bit, not surprisingly the last example is inaccurate past 16 significant digits on 32 bit (ditto p2js), and hence omitted.
Line 505:
=={{header|Raku}}==
It's a built-in.
<syntaxhighlight lang="raku"
printf "%35s - Period is %-5s: %s%s\n", $rat.nude.join('/'), .[1].chars, .[0], (.[1].comb Z~ "\c[COMBINING OVERLINE]" xx *).join
given $rat.base-repeating
}</
{{out}}
<pre style="overflow:auto;white-space:revert;"> 0/1 - Period is 0 : 0
Line 524:
=={{header|Vlang}}==
{{trans|wren}}
<
const big_ten = big.integer_from_int(10)
Line 588:
println('period is ${res[2]}\n')
}
}</
{{out}}
<pre>
Line 595:
=={{header|Wren}}==
This is based on the Python code [http://codepad.org/hKboFPd2 here].
<
var divide = Fn.new { |m, n|
Line 649:
System.print("Repetend is '%(res[1])'")
System.print("Period is %(res[2])\n")
}</
{{out}}
|