/** This tests the sqrtNearestInteger function. */ // Try near powers of 2 first for bits=3 to 100 { for offset = -5 to 5 { n = 2^bits + offset i = sqrtNearestInteger[n] if (i^2 > n) or ((i+1)^2 <= n) println["Error at $n, i=$i"] } } // Random numbers of varying magnitudes that will exercise the int, long, // and BigDecimal versions. for tries = 1 to 100 million { bits = random[1,100] n = randomBits[bits] i = sqrtNearestInteger[n] if (i^2 > n) or ((i+1)^2 <= n) println["Error at $n, i=$i"] }