Category talk:Wren-big: Difference between revisions
Content added Content deleted
(→Source code: Bug fix.) |
(→Source code: Improved BigInt.isqrt method - up to 3x faster than before.) |
||
Line 1,015: | Line 1,015: | ||
// r.square <= this. Throws an error if the current instance is negative. |
// r.square <= this. Throws an error if the current instance is negative. |
||
isqrt { |
isqrt { |
||
if ( |
if (isNegative) Fiber.abort("Cannot take the square root of a negative number.") |
||
if (isSmall) return BigInt.small_(toSmall.sqrt.floor) |
|||
var one = BigInt.one |
|||
var |
var a = one << ((bitLength + one) >> one) |
||
while (true) { |
|||
var b = (this/a + a) >> one |
|||
if (b >= a) return a |
|||
a = b |
|||
r = r / 2 |
|||
if (t >= 0) { |
|||
z = t |
|||
r = r + q |
|||
} |
|||
} |
} |
||
} |
|||
} |
|||
// Returns a list containing the quotient and the remainder after dividing the current instance |
// Returns a list containing the quotient and the remainder after dividing the current instance |