Jump to content

Category talk:Wren-big: Difference between revisions

→‎Source code: Improved BigInt.isqrt method - up to 3x faster than before.
(→‎Source code: Bug fix.)
(→‎Source code: Improved BigInt.isqrt method - up to 3x faster than before.)
Line 1,015:
// r.square <= this. Throws an error if the current instance is negative.
isqrt {
if (this.isNegative) Fiber.abort("Cannot take the square root of a negative number.")
varif q(isSmall) =return BigInt.onesmall_(toSmall.sqrt.floor)
whilevar (qone <= this) q = q * 4BigInt.one
var za = this.copyone << ((bitLength + one) >> one)
varwhile r(true) = BigInt.zero{
while var b = (qthis/a >+ BigInt.onea) {>> one
qif (b >= qa) /return 4a
var ta = z - r - qb
r = r / 2
if (t >= 0) {
z = t
r = r + q
}
}
} return r
}
// Returns a list containing the quotient and the remainder after dividing the current instance
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.