Category talk:Wren-rat: Difference between revisions

→‎Source code: Removed type aliases and Rat.maxSafe methods which are no longer needed.
(→‎Source code: Bug fix - wrong name for toFloat function.)
(→‎Source code: Removed type aliases and Rat.maxSafe methods which are no longer needed.)
Line 2:
<lang ecmascript>/* Module "rat.wren" */
 
import "./trait" for Comparable
 
/* Rat represents a rational number as an integral numerator and (non-zero) denominator
Line 8:
*/
class Rat is Comparable {
// Maximum safe rational number = 2^53 - 1.
static maxSafe { Rat.fromInt(9007199254740991) }
 
// Private helper function to check that 'o' is a suitable type and throw an error otherwise.
// Numbers and numeric strings are returned as rationals.
Line 222 ⟶ 219:
static max(a) { a.reduce { |acc, x| (x > acc) ? x : acc } }
static min(a) { a.reduce { |acc, x| (x < acc) ? x : acc } }
}</lang>
}
 
// Type aliases for classes in case of any name clashes with other modules.
var Rat_Rat = Rat
var Rat_Rats = Rats
var Rat_Comparable = Comparable // in case imported indirectly</lang>
9,483

edits