Jump to content

Isqrt (integer square root) of X: Difference between revisions

no edit summary
m (RPL comments)
No edit summary
Line 3,314:
19 | 11398895185373143 | 106765608
21 | 558545864083284007 | 747359260</pre>
 
=={{header|M2000 Interpreter}}==
Using various types up to 7^35
 
<syntaxhighlight lang="m2000 interpreter">
module integer_square_root (f=-2) {
function IntSqrt(x as long long) {
long long q=1, z=x, t, r
do q*=4&& : until (q>x)
while q>1&&
q|div 4&&:t=z-r-q:r|div 2&&
if t>-1&& then z=t:r+= q
end while
=r
}
long i
print #f, "The integer square root of integers from 0 to 65 are:"
for i=0 to 65
print #f, IntSqrt(i)+" ";
next
print #f
print #f, "Using Long Long Type"
print #f, "The integer square roots of powers of 7 from 7^1 up to 7^21 are:"
for i=1 to 21 step 2 {
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(7&&^i))+" of 7^"+i+" ("+(7&&^I)+")"
}
print #f
function IntSqrt(x as decimal) {
double q=1, z=x, t, r
do q*=4 : until (q>x)
while q>1
q/=4:t=z-r-q:r/=2
if t>-1 then z=t:r+= q
end while
=r
}
print #f, "Using Decimal Type"
print #f, "The integer square roots of powers of 7 from 7^23 up to 7^33 are:"
decimal j,p
for i=23 to 33 step 2 {
p=1:for j=1 to i:p*=7@:next
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(p))+" of 7^"+i+" ("+p+")"
}
print #f
function IntSqrt(x as double) {
double q=1, z=x, t, r
do q*=4 : until (q>x)
while q>1
q/=4:t=z-r-q:r/=2
if t>-1 then z=t:r+= q
end while
=r
}
print #f, "Using Double Type"
print #f, "The integer square roots of powers of 7 from 7^19 up to 7^35 are:"
for i=19 to 35 step 2 {
print #f, "IntSqrt(7^"+i+")="+(IntSqrt(7^i))+" of 7^"+i+" ("+(7^i)+")"
}
print #f
}
open "" for output as #f // f = -2 now, direct output to screen
integer_square_root
close #f
open "out.txt" for output as #f
integer_square_root f
close #f
win "notepad", dir$+"out.txt"
</syntaxhighlight>
{{out}}
<pre>
The integer square root of integers from 0 to 65 are:
0 1 1 1 2 2 2 2 2 3 3 3 3 3 3 3 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5 5 5 6 6 6 6 6 6 6 6 6 6 6 6 6 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 8 8
Using Long Long Type
The integer square roots of powers of 7 from 7^1 up to 7^21 are:
IntSqrt(7^1)=2 of 7^1 (7)
IntSqrt(7^3)=18 of 7^3 (343)
IntSqrt(7^5)=129 of 7^5 (16807)
IntSqrt(7^7)=907 of 7^7 (823543)
IntSqrt(7^9)=6352 of 7^9 (40353607)
IntSqrt(7^11)=44467 of 7^11 (1977326743)
IntSqrt(7^13)=311269 of 7^13 (96889010407)
IntSqrt(7^15)=2178889 of 7^15 (4747561509943)
IntSqrt(7^17)=15252229 of 7^17 (232630513987207)
IntSqrt(7^19)=106765608 of 7^19 (11398895185373143)
IntSqrt(7^21)=747359260 of 7^21 (558545864083284007)
 
Using Decimal Type
The integer square roots of powers of 7 from 7^23 up to 7^33 are:
IntSqrt(7^23)=5231514822 of 7^23 (27368747340080916343)
IntSqrt(7^25)=36620603758 of 7^25 (1341068619663964900807)
IntSqrt(7^27)=256344226312 of 7^27 (65712362363534280139543)
IntSqrt(7^29)=1794409584184 of 7^29 (3219905755813179726837607)
IntSqrt(7^31)=12560867089291 of 7^31 (157775382034845806615042743)
IntSqrt(7^33)=87926069625040 of 7^33 (7730993719707444524137094407)
 
Using Double Type
The integer square roots of powers of 7 from 7^19 up to 7^35 are:
IntSqrt(7^19)=106765608 of 7^19 (1.13988951853731E+16)
IntSqrt(7^21)=747359260 of 7^21 (5.58545864083284E+17)
IntSqrt(7^23)=5231514822 of 7^23 (2.73687473400809E+19)
IntSqrt(7^25)=36620603758 of 7^25 (1.34106861966396E+21)
IntSqrt(7^27)=256344226312 of 7^27 (6.57123623635343E+22)
IntSqrt(7^29)=1794409584184 of 7^29 (3.21990575581318E+24)
IntSqrt(7^31)=12560867089291 of 7^31 (1.57775382034846E+26)
IntSqrt(7^33)=87926069625040 of 7^33 (7.73099371970744E+27)
IntSqrt(7^35)=615482487375282 of 7^35 (3.78818692265665E+29)
 
 
</pre>
 
=={{header|MAD}}==
404

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.