mersenne.frink

View or download mersenne.frink in plain text format

// Program to calculate the value of the largest known Mersenne prime.


//p=13466917

//p=20_996_011   // Largest known as of Nov. 2003
//p=25_964_951    // Largest known as of Feb. 2005.
// p = 30_402_457    // Largest known as of Dec. 2005.
// p = 32_582_657   // Largest as of September 2006
// p = 37_156_667   // Found in September 2008
//p = 43_112_609   // Also found (slightly earlier! in September 2008)
// p = 57_885_161
p = 74_207_281       // Found in January 2016

start = now[]
m=2^p
end = now[]
println["Time to perform exponent: " + format[end-start, "s", 3]]

start = now[]
mp = m - 1
end = now[]

println["Time to perform subtraction: " + format[end-start, "s", 3] + "\n"]
println["2^" + p + " - 1 =\n"]


start = now[]
out = newToString[mp]   // Get string representation
end = now[]

//println[out]

println["Time to format (w/Frink optimizations): " + format[end-start, "s", 3] + "\n"]
println["Length is " + length[out] + " decimal digits."]

start = now[]
mp2 = parseInt[out]
end = now[]

if mp2 != mp
   println["***** ROUND-TRIP ERROR ******"]

println["Time to parse (w/Frink optimizations): " + format[end-start, "s", 3] + "\n"]


start = now[]
out = oldToString[mp]   // Get string representation
end = now[]

//println[out]

println["Time to format (native): " + format[end-start, "s", 3] + "\n"]

start = now[]
out = "$mp"   // Get string representation using automatically-selected algo.
end = now[]

//println[out]

println["Time to format (w/automatic algorithm): " + format[end-start, "s", 3] + "\n"]

start = now[]
mp3 = newJava["java.math.BigInteger", [out]]
end = now[]

//println[out]

println["Time to parse (native): " + format[end-start, "s", 3] + "\n"]
if mp3 != mp
   println["***** ROUND-TRIP ERROR ******"]


View or download mersenne.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 17651 days, 5 hours, 12 minutes ago.