Category talk:Wren-big: Difference between revisions

Content added Content deleted
(→‎Source code: Added BigRat.cbrt method.)
(→‎Source code: Added BigRat.cube, tweaked sqrt and cbrt methods.)
Line 1,754: Line 1,754:
// Returns the square of the current instance.
// Returns the square of the current instance.
square { BigRat.new(_n * _n , _d *_d) }
square { BigRat.new(_n * _n , _d *_d) }

// Returns the cube of the current instance.
cube { square * this }


// Returns the square root of the current instance to 'digits' decimal places.
// Returns the square root of the current instance to 'digits' decimal places.
Line 1,763: Line 1,766:
digits = digits + 5
digits = digits + 5
var powd = BigInt.ten.pow(digits)
var powd = BigInt.ten.pow(digits)
var sqtd = (powd.square * _n / _d).isqrt
var sqtd = (powd.square * _n / _d).iroot(2)
return BigRat.new(sqtd, powd)
return BigRat.new(sqtd, powd)
}
}
Line 1,778: Line 1,781:
digits = digits + 5
digits = digits + 5
var powd = BigInt.ten.pow(digits)
var powd = BigInt.ten.pow(digits)
var cbtd = (powd.cube * _n / _d).icbrt
var cbtd = (powd.cube * _n / _d).iroot(3)
return BigRat.new(cbtd, powd)
return BigRat.new(cbtd, powd)
}
}