Numbers
Number → Object
Any numeric value. Integer and Double are both Numbers, though presumeably quotients and complex numbers would also be valid.
a + b → Number | a is-a?: Number | b is-a?: Number
Adds a and b. If either are Rationals, it returns a Rational; otherwise, if either are Doubles, it returns a Double.
a - b → Number | a is-a?: Number | b is-a?: Number
Subtracts b from a. If either are Rationals, it returns a Rational; otherwise, if either are Doubles, it returns a Double.
a * b → Number | a is-a?: Number | b is-a?: Number
Multiplies a by b. If either are Rationals, it returns a Rational; otherwise, if either are Doubles, it returns a Double.
a / b → Number | a is-a?: Number | b is-a?: Number
Divides a by b. If either are Rationals, it returns a Rational; otherwise, if either are Doubles, it returns a Double. If both are Integers, it performs integer division.
a ^ b → Number | a is-a?: Number | (b is-a?: Integer) || (b is-a?: Double)
Raises a to the power of b. If either are Doubles, it returns a Double. If a is a Rational, b must be an Integer.
a quotient: b → Integer | a is-a?: Integer | b is-a?: Integer
Returns the quotient of dividing a by b.
Example:
> 22 quotient: 5 4
a remainder: b → Integer | a is-a?: Integer | b is-a?: Integer
Returns the remainder of dividing a by b.
Example:
> 22 remainder: 5 2
n reciprocal → Number | n is-a?: Number
Returns the reciprocal of n, returning either a Double (if n is an Integer or Double) or a Rational (if n is a Rational).
Example:
> 2 reciprocal 0.5 > 0.5 reciprocal 2.0 > 3/4 reciprocal 4/3
r approximate → Double | r is-a?: Rational
Approximates r as an (inexact) Double.
Example:
> 3/4 approximate 0.75
n rationalize → Rational | (n is-a?: Integer) || (n is-a?: Double)
Convert an Integer or an inexact Double into the simplest rational number within 0.001 of n.
Example:
> 5 rationalize 5/1 > 0.5 rationalize 1/2 > 0.1234 rationalize 6/49
n rationalize: epsilon → Rational | (n is-a?: Integer) || (n is-a?: Double)
Convert an Integer or an inexact Double into the simplest rational number within epsilon of n.
Example:
> 0.1234 rationalize: 1.0 0/1 > 0.1234 rationalize: 0.1 1/5 > 0.1234 rationalize: 0.01 1/8 > 0.1234 rationalize: 0.001 6/49 > 0.1234 rationalize: 0.0001 10/81 > 0.1234 rationalize: 0.0 8891907104280307/72057594037927936