Download or view karatsubaTest.frink in plain text format
use karatsuba.frink
digits = 100
s = karatsubaFloat[2,digits]
println[s]
setPrecision[digits]
println[s^2]
digits = 100
start = now[]
s = karatsubaFloat[640320, digits]
end = now[]
println["Time is " + (end-start)]
setPrecision[digits]
println[s^2]
digits = 100
start = now[]
s = karatsubaFloat[10^1000 + 1, digits]
end = now[]
println["Time is " + (end-start)]
setPrecision[digits]
println[s^2]
digits = 1000
start = now[]
s = karatsubaFloat[640320, digits]
end = now[]
println["Time is " + (end-start)]
setPrecision[digits]
//println[s^2]
for bits = 2 to million
{
// Test around 2^n bits
for add = -3 to 3
testNum[2^bits + add]
// Test random bits of this length
for n = 1 to 10
testNum[randomBits[bits]]
if bits mod 1000 == 0
print["$bits "]
}
println["done"]
// Modified to only print on failures
testNum[n] :=
{
[s, r] = sqrtRem[n]
if (s^2 + r) != n or r < 0
{
t = bitLength[n] % 4
if t == 2 or t == 1
k = "yep"
else
k = base2[n]
println["$n: bad $k"]
}
}
Download or view karatsubaTest.frink in plain text format
This is a program written in the programming language Frink.
For more information, view the Frink
Documentation or see More Sample Frink Programs.
Alan Eliasen was born 20136 days, 3 hours, 48 minutes ago.