Category talk:Wren-big: Difference between revisions

Content added Content deleted
(→‎Source code: Added testBit method to BigInt.)
(→‎Source code: Bug fix.)
Line 114: Line 114:
static integerLogarithm_(value, base) {
static integerLogarithm_(value, base) {
if (base <= value) {
if (base <= value) {
System.write("") // guard against VM recursion bug
var tmp = integerLogarithm_(value, base.square)
var tmp = integerLogarithm_(value, base.square)
var p = tmp[0]
var p = tmp[0]
Line 344: Line 343:
// Private method to multiply two lists 'x' and 'y' using the Karatsuba algorithm.
// Private method to multiply two lists 'x' and 'y' using the Karatsuba algorithm.
static multiplyKaratsuba_(x, y) {
static multiplyKaratsuba_(x, y) {
var n = (x.count > y.count) ? x.count : y.count
var n = (x.count > y.count) ? y.count : x.count
if (n <= 30) return multiplyLong_(x, y)
if (n <= 30) return multiplyLong_(x, y)
n = (n/2).ceil
n = (n/2).floor
var a = x[0...n]
var a = x[0...n]
var b = x[n..-1]
var b = x[n..-1]
var c = y[0...n]
var c = y[0...n]
var d = y[n..-1]
var d = y[n..-1]
System.write("") // guard against VM recursion bug
var ac = multiplyKaratsuba_(a, c)
var ac = multiplyKaratsuba_(a, c)
var bd = multiplyKaratsuba_(b, d)
var bd = multiplyKaratsuba_(b, d)