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

Content added Content deleted
m (Swift - reduced output font size)
m (→‎{{header|VTL-2}}: VTL-2 uses unsigned arithmetic, so can handle the root of 7^5)
Line 6,595: Line 6,595:


=={{header|VTL-2}}==
=={{header|VTL-2}}==
The ISQRT routine starts at line 2000. As with other 16-bit language samples, only the roots of 7^1 and 7^3 are shown as Q would overflow when the root of 7^5 is calculated.
The ISQRT routine starts at line 2000. As VTL-2 only has unsigned 16-bit arithmetic, only the roots of 7^1, 7^3 and 7^5 are shown as 7^7 is too large.
<syntaxhighlight lang="vtl2">
<syntaxhighlight lang="vtl2">
1000 X=0
1000 X=0
Line 6,617: Line 6,617:
1180 X=X*49
1180 X=X*49
1190 P=P+2
1190 P=P+2
1200 #=P<4*1100
1200 #=P<6*1100
1210 #=9999
1210 #=9999
2000 A=!
2000 A=!
Line 6,642: Line 6,642:
Root 7^1(7) = 2
Root 7^1(7) = 2
Root 7^3(343) = 18
Root 7^3(343) = 18
Root 7^5(16807) = 129
</pre>
</pre>