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 { |
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 |
var sign = _n.isNegative ? "-" : "" |
||
var |
var nn = _n.abs |
||
var q = nn / _d |
|||
var r = nn % _d |
|||
return sign + q.toString + "_" + r.toString + "/" + _d.toString |
|||
} |
} |
||