Next: 3.8 Collections
Up: 3 The Slate World
Previous: 3.6 Symbols
Contents
Index
Subsections
3.7.1 Basic Types
- Magnitude
- the abstract protocol
for linearly-comparable objects, following <, >,
<=, >=, and =.
- Number
- the abstract type of dimensionless
quantities.
- Integer
- integral quantities, generally.
- SmallInteger
- 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.
- BigInteger
- larger Integers,
implemented by wrapping ByteArrays
with the appropriate behavior.
- Fraction
- An exact representation
of a quotient, or rational number.
- Float
- A low-level floating-point
numeric representation, being inexact. Floats are currently only implemented
as SingleFloat, a single-precision
floating-point number representation.
- Complex
- A complex number, similar
to a pair of real numbers.
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.
- zero
- The zero element for the type
of number.
- isZero
- Whether the number is the
zero element for its type.
- isPositive/isNegative
- Whether
it's positive or negative.
- abs
- The absolute value of the number.
- sign
- The sign of the number.
- negated
- Returns -x for
x.
- gcd:
- Greatest common divisor.
- lcm:
- Least common multiple.
- factorial
- Factorial.
- mod:/rem:/quo:
- Modulo
division, remainder, and quotient.
- reciprocal
- Constructs a new
fraction reciprocal.
- min:
- The lesser of the arguments.
The least in cases of min:min:.
- max:
- The greater of the arguments.
The greatest in cases of max:max:.
- a between: b and: c
- Whether
a is between b and c.
- truncated/fractionPart
- answers
the greatest integer less than the number, and the corresponding difference
as a fraction (or a float for Float).
- reduced
- 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.
- readFrom:
- 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.
- PositiveInfinity
- is
greater than any other Magnitude.
- NegativeInfinity
- is lesser
than any other Magnitude.
- LargeUnbounded
- A Magnitude
designed to represent non-infinite, but non-bounded (``as large
as you like'') quantities.
- PositiveEpsilon
- is as
small as you like, but positive and greater than zero.
- NegativeEpsilon
- is as
small as you like, but negative and lesser than zero.
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: 3.8 Collections
Up: 3 The Slate World
Previous: 3.6 Symbols
Contents
Index
Brian Rice
2005-11-21