Category talk:Wren-big: Difference between revisions

→‎Source code: Added BigRat.sqrt method.
(→‎Source code: Added an option to truncate rather than round to the BigRat.toDecimal method.)
(→‎Source code: Added BigRat.sqrt method.)
Line 1,477:
// Returns the square of the current instance.
square { BigRat.new(_n * _n , _d *_d) }
 
// Returns the square root of the current instance to 'digits' decimal places.
// Five more decimals is used to try to ensure accuracy though this is not guaranteed.
sqrt(digits) {
if (!((digits is Num) && digits.isInteger && digits >= 0)) {
Fiber.abort("Digits must be a non-negative integer.")
}
digits = digits + 5
var powd = BigInt.ten.pow(digits)
var sqtd = (powd.square * _n / _d).isqrt
return BigRat.new(sqtd, powd)
}
// Convenience version of the above method which uses 14 decimal places.
sqrt { sqrt(14) }
 
// Other methods.
9,476

edits