next up previous contents index
Next: 3.8 Collections Up: 3 The Slate World Previous: 3.6 Symbols   Contents   Index


3.7 Magnitudes and Numbers

3.7.1 Basic Types

the abstract protocol for linearly-comparable objects, following <, >, <=, >=, and =.
the abstract type of dimensionless quantities.
integral quantities, generally.
machine-word-limited integer values (minus 1 bit for the immediate-value flag). Their normal protocol will not produce errors inconsistent with mathematic behavior of Integers, however: instead of overflows, BigInteger objects of the appropriate value are returned.
larger Integers, implemented by wrapping ByteArrays with the appropriate behavior.
An exact representation of a quotient, or rational number.
A low-level floating-point numeric representation, being inexact. Floats are currently only implemented as SingleFloat, a single-precision floating-point number representation.
A complex number, similar to a pair of real numbers.

3.7.2 Basic Operations

All of the normal arithmetic operations (i.e. +, -, *, /) are supported primitively between elements of the same type. Type coercion has to be done entirely in code; no implicit coercions are performed by the virtual machine. However, the standard library includes methods which perform this coercion. The interpreter also transparently provides unlimited-size integers, although the bootstrapped system may not do so implicitly.

The following are the rest of the primitive operations, given with an indication of their "signatures":

Float raisedTo: Float
is simple floating-point exponentiation.
Integer as: Float
extends an integer into a float.
Float as: Integer
truncates a float.
Integer bitOr: Integer
performs bitwise logical OR.
Integer bitXor: Integer
performs bitwise logical XOR.
Integer bitAnd: Integer
performs bitwise logical AND.
Integer bitShift: Integer
performs bitwise logical right-shift (left-shift if negative).
Integer bitNot
performs bitwise logical NOT.
Integer >> Integer
performs logical right-shift.
Integer << Integer
performs logical left-shift.
Integer quo: Integer
returns a quotient (integer division).
Many more useful methods are defined, such as mod:, reciprocal, min:, max:, between:and:, lcm:, and gcd:. Slate also works with Fractions when dividing Integers, keeping them lazily reduced.

3.7.3 Non-core Operations

The zero element for the type of number.
Whether the number is the zero element for its type.
Whether it's positive or negative.
The absolute value of the number.
The sign of the number.
Returns -x for x.
Greatest common divisor.
Least common multiple.
Modulo division, remainder, and quotient.
Constructs a new fraction reciprocal.
The lesser of the arguments. The least in cases of min:min:.
The greater of the arguments. The greatest in cases of max:max:.
a between: b and: c
Whether a is between b and c.
answers the greatest integer less than the number, and the corresponding difference as a fraction (or a float for Float).
Only defined on Fraction, this is the lazily-applied reducer; it will be invoked automatically for arithmetic operations as necessary, but is useful when only the reduced form is needed.
This takes a String or a Stream with compatible contents and parses the first available data as the type of the argument. If the return value is not the same as the argument type, an error is signalled (beyond any normal parsing errors). If the value is valid, it is returned; otherwise only Nil will be available.

3.7.4 Limit Numerics

is greater than any other Magnitude.
is lesser than any other Magnitude.
A Magnitude designed to represent non-infinite, but non-bounded (``as large as you like'') quantities.
is as small as you like, but positive and greater than zero.
is as small as you like, but negative and lesser than zero.

3.7.5 Dimensioned Units

There is an entire system for handling dimensioned units and their various combinations and mathematical operations. There is included support for SI units, and common English units; furthermore, any object may conceivably be used as a base unit. See the 'src/lib/dimensioned.slate' file for an overview.

next up previous contents index
Next: 3.8 Collections Up: 3 The Slate World Previous: 3.6 Symbols   Contents   Index
Brian Rice 2005-11-21