baseConversionTest.frink

View or download baseConversionTest.frink in plain text format

// Program to test correctness of base conversions.
// This performs a round-trip conversion of random numbers to and from
// all bases.

upper = 100000
stepsize = upper div 100
for n = 1 to 100000
{
   if n mod stepsize == 0
      println[n div stepsize + "%"]
   
   b=random[2,26]
   b = b * random[[-1,1]]
   exp=random[300, 2000]
   m = b^exp
   
   for addend = -2 to 2
   {
      mp = m + addend
      
      for base = 2 to 36
      {
 out1 = newToString[mp, base]   // Get string representation

 mp2 = parseInt[out1, base]

 if mp != mp2
    println["*DISCREPANCY: $b^$exp + $addend in base $base"]
      }
   }
}

println["done"]


View or download baseConversionTest.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 17646 days, 9 hours, 40 minutes ago.