Category talk:Wren-rat: Difference between revisions
→Source code: Bug fix - wrong name for toFloat function.
(→Source code: Various changes or additions to make the Rat class more consistent with the new BigRat class.) |
(→Source code: Bug fix - wrong name for toFloat function.) |
||
Line 132:
// Basic properties.
num { _n } // numerator
den { _d } // denominator
ratio { [_n, _d] } // a two element list of the above
isInteger {
isPositive { _n > 0 } // checks if positive
isNegative { _n < 0 } // checks if negative
isUnit { _n.abs == 1 } // checks if plus or minus one
isZero { _n == 0 } // checks if zero
// Rounding methods (similar to those in Num class).
Line 146:
truncate { Rat.fromInt(toFloat.truncate) } // lower integer, towards zero
round { Rat.fromInt(toFloat.round) } // nearer integer
fraction { this - truncate } // fractional part (same sign as this.num)
// Reciprocal
|