Integer roots: Difference between revisions
→{{header|Phix}}: bigatom -> mpfr
(→{{header|Phix}}: bigatom -> mpfr) |
|||
Line 665:
=={{header|Phix}}==
{{
<lang Phix>include
function integer_root(integer n, object
-- yields the nth root of A, adapted from https://en.wikipedia.org/wiki/Nth_root_algorithm
x = mpz_init(),
delta = mpz_init()
A = mpz_init(A)
while true do
if mpz_cmp_si(delta,0)=
end while
return
end function
printf(1,"3rd root of 8 = %s\n", {integer_root(3,8)})
printf(1,"3rd root of 9 = %s\n", {integer_root(3,9)})
string s = integer_root(2,"
printf(1,"First digits of the square root of 2: %s\n", {shorten(s)})
s = integer_root(3,"2"&repeat('0',6000))
printf(1,"First
{{out}}
<pre>
3rd root of 8 = 2
3rd root of 9 = 2
First
First digits of the cube root of 2: 1259921049894873164...2546828353183047061 (2001 digits)
</pre>
|