Numbers

Number  Object

Any numeric value. Integer and Double are both Numbers, though presumeably quotients and complex numbers would also be valid.

Integer  Object

Integral numbers with no decimal segment.

Example:

1
Double  Object

Double-precision floating-point numbers.

Example:

1.0
Rational  Object

Exact ratios between integers.

Example:

22/7
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.

Example:

> 1 + 2
3
> 1.0 + 2.0
3.0
> 1/2 + 3/4
5/4
> 1/2 + 2
5/2
> 1.0 + -2
-1.0
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.

Example:

> 1 - 2
-1
> 1.0 - 2.0
-1.0
> 1/2 - 3/4
-1/4
> 1/2 - 2.5
-2/1
> 1.0 - -2
3.0
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.

Example:

> 1 * 2
2
> 1.0 * 2.0
2.0
> 1/2 * 3/4
3/8
> 1/2 * 2.5
5/4
> 1.0 * -2
-2.0
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.

Example:

> 1 / 2
0
> 1.0 / 2.0
0.5
> 1/2 / 3/4
2/3
> 1/2 / 2.5
1/5
> 1.0 / -2
-0.5
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.

Example:

> 1 ^ 2
1
> 1.0 ^ 2.0
1.0
> 1/2 ^ 4
1/16
> 1.0 ^ -2
1.0
a % b  Integer
  | a is-a?: Integer
  | b is-a?: Integer

Modulus operator.

Example:

> 3 % 2
1
> 6 % 2
0
> 7 % -2
-1
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 sqrt  Double
  | (n is-a?: Integer) || (n is-a?: Double)

Returns the square root of n.

Example:

> 5 sqrt
2.23606797749979
> 5.8 sqrt
2.4083189157584592
d ceiling  Integer
  | d is-a?: Double

Converts d into an Integer by rounding up.

Example:

> 1.9 ceiling
2
> 1.1 ceiling
2
> 1.0 ceiling
1
d round  Integer
  | d is-a?: Double

Rounds d down or up to the nearest Integer.

Example:

> 1.9 round
2
> 1.5 round
2
> 1.4 round
1
> 1.0 round
1
d floor  Integer
  | d is-a?: Double

Converts d into an Integer by rounding down.

Example:

> 1.9 floor
1
> 1.1 floor
1
> 1.0 floor
1
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 numerator  Integer
  | r is-a?: Rational

Returns r's numerator.

Example:

> 3/4 numerator
3
r denominator  Integer
  | r is-a?: Rational

Returns r's denominator.

Example:

> 3/4 denominator
4
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
d as: Integer  Integer
  | d is-a?: Double

Converts d into an Integer by sending floor to it.

Example:

> 0.75 as: Integer
0
> 1.75 as: Integer
1
d as: Rational  Rational
  | d is-a?: Double

Converts d into a Rational by sending rationalize to it.

Example:

> 0.75 as: Rational
3/4
i as: Double  Double
  | i is-a?: Integer

Converts i into a Double.

Example:

> 4 as: Double
4.0
i as: Rational  Rational
  | i is-a?: Integer

Converts i into a Rational.

Example:

> 4 as: Rational
4/1
r as: Double  Double
  | r is-a?: Rational

Converts r into a Double by sending approximate to it.

Example:

> 4/3 as: Double
1.3333333333333333
r as: Integer  Integer
  | r is-a?: Rational

Converts r into an Integer by sending approximate and floor to it.

Example:

> 4/3 as: Integer
1
n even?  Boolean
  | n is-a?: Integer

Is n even?.

n odd?  Boolean
  | n is-a?: Integer

Is n odd?.

a divides?: b  Boolean
  | a is-a?: Integer
  | b is-a?: Integer

Does a divide b?

a divisible-by?: b  Boolean
  | a is-a?: Integer
  | b is-a?: Integer

Alias for b divides?: a.