Category talk:Wren-big: Difference between revisions

Content added Content deleted
(→‎Source code: Fixed bug and aligned BigRat.pow with Rat.pow method.)
(→‎Source code: Rewrote BigRat.toFloat and toMixedString methods which were buggy previously.)
Line 2,014: Line 2,014:
// Converts the current instance to a Num where possible.
// Converts the current instance to a Num where possible.
// Will probably lose accuracy if the numerator and/or denominator are not 'small'.
// Will probably lose accuracy if the numerator and/or denominator are not 'small'.
toFloat { Num.fromString(this.toDecimal(14)) }
toFloat { _n.toNum / _d.toNum }


// Converts the current instance to an integer where possible with any fractional part truncated.
// Converts the current instance to an integer where possible with any fractional part truncated.
Line 2,072: Line 2,072:
// Returns a string represenation of this instance in the form "i_n/d" where 'i' is an integer.
// Returns a string represenation of this instance in the form "i_n/d" where 'i' is an integer.
toMixedString {
toMixedString {
var q = _n / _d
var sign = _n.isNegative ? "-" : ""
var r = _n % _d
var nn = _n.abs
if (r.isNegative) r = -r
var q = nn / _d
return q.toString + "_" + r.toString + "/" + _d.toString
var r = nn % _d
return sign + q.toString + "_" + r.toString + "/" + _d.toString
}
}