next prev up top content index

11 The Built-In Classes

Numbers

Dylan provides a variety of numeric classes. Classes under <complex> are sealed, so that numeric operations on them can be highly optimized. User defined numeric classes will be subclasses of <number>.

Figure 11-3 shows the built-in number classes and some of their characteristics.

Figure 11-3 The Number Classes

Number Class Hierarchy
S – Sealed P – Primary C – Concrete I – Instantiable
O – Open F – Free A – Abstract U – Uninstantiable

General Numbers

<number> [Open Abstract Class]


The class of all numbers.

Superclasses:

<object>

Init-keywords:

None.

Operations:

None.

Description:

The class of all numbers.

The class <number> is open, to allow programmers to create additional numeric classes. The built-in numeric operations do not provide default implementations for <number>, but for <complex>, a sealed subclass of <number>.

Complex Numbers

<complex> [Sealed Abstract Class]


The class of complex numbers.

Superclasses:

<number>

Init-keywords:

None.

Description:

The sealed superclass of all built-in numbers, including real numbers. There are no non-real subclasses of <complex> defined by the language, but implementations may define such subclasses. Because <complex> and all its defined subclasses are sealed, implementation-defined subclasses may be added efficiently.

Many built-in functions are defined to have methods on <complex>. This means that the function is defined on all built-in subclasses of <complex>. It does not imply that there is a single method specialized on the <complex> class.

Operations:

The class <complex> provides implementations for the following functions:

Table 11-10 Methods on <complex>

Function

Description

Page

=

Compares two objects for equality.

269

zero?

Tests for the property of being equal to zero.

275

+

Returns the sum of its arguments.

277

*

Returns the product of its arguments.

277

-

Returns the difference of its arguments.

278

/

Returns the quotient of its arguments.

278

^

Raises an object to a specified power.

283

Reals

<real> [Sealed Abstract Class]


The class of real numbers.

Superclasses:

<complex>

Init-keywords:

None.

Description:

The class of real numbers.

Operations:

The class <real> provides implementations for the following functions:

Table 11-11 Functions on <real>

Function

Description

Page

floor

Truncates a real number toward negative infinity.

279

ceiling

Truncates a real number toward positive infinity.

280

round

Rounds a real number toward the nearest mathematical integer.

280

truncate

Truncates a real number toward zero.

280

floor/

Returns the floor of the quotient of two numbers.

281

ceiling/

Returns the ceiling of the quotient of two numbers.

281

round/

Rounds off the quotient of two numbers.

282

truncate/

Returns the truncated quotient of two numbers.

282

modulo

Returns the second value of floor/.

282

remainder

Returns the second value of truncate/.

283

Table 11-12 Methods on <real>

Function

Description

Page

<

Returns true if its first operand is less than its second operand.

271

abs

Returns the absolute value of its argument.

284

positive?

Tests for the property of being positive.

276

negative?

Tests for the property of being negative.

276

integral?

Tests for the property of being integral.

276

negative

Returns the negation of an object.

279

Floats

The classes <single-float> and <double-float> are intended but not required to be the corresponding IEEE types. The class <extended-float> is intended but not required to have more range and/or precision than <double-float>.

If an implementation has fewer than three floating point classes, the names <single-float>, <double-float> and <extended-float> may all refer to the same object.

<float> [Sealed Abstract Class]


The class of floating-point numbers.

Superclasses:

<real>

Init-keywords:

None.

Description:

The class of all floating-point numbers. This class is abstract. All floating point numbers will be instances of some concrete subclass of this class.

Operations:

None.

<single-float> [Sealed Class]


The class of single-precision floating-point numbers.

Superclasses:

<float>

Init-keywords:

None.

Description:

The class of single-precision floating-point numbers. This class is intended but not required to correspond to IEEE single-precision.

Operations:

None.

<double-float> [Sealed Class]


The class of double-precision floating-point numbers.

Superclasses:

<float>

Init-keywords:

None.

Description:

The class of double-precision floating-point numbers. This class is intended but not required to correspond to IEEE double-precision.

Operations:

None.

<extended-float> [Sealed Class]


The class of extended-precision floating-point numbers.

Superclasses:

<float>

Init-keywords:

None.

Description:

The class of extended-precision floating-point numbers. This class is intended but not required to provide more precision that <double-float>.

Operations:

None.

Rationals

<rational> [Sealed Abstract Class]


The class of rational numbers.

Superclasses:

<real>

Init-keywords:

None.

Description:

The class of rational numbers.

Operations:

None.

Integers

<integer> [Sealed Class]


The class of integers.

Superclasses:

<rational>

Init-keywords:

None.

Description:

The class of integers.

Implementations are required to support integers with at least 28 bits of precision. The overflow and underflow behavior is implementation-defined. (Some implementations may choose to have integers of unlimited size, but this is not required.)

The result of dividing two integers with / is implementation defined. Portable programs should use floor/, ceiling/, round/, or truncate/ to divide two integers.

Operations:

The class <integer> provides the following operations:

Table 11-13 Functions on <integer>

Function

Description

Page

odd?

Tests for the property of being an odd number.

275

even?

Tests for the property of being an even number.

275

logior

Returns the bitwise inclusive or of its integer arguments.

284

logxor

Returns the bitwise exclusive or of its integer arguments.

284

logand

Returns the bitwise and of its integer arguments.

285

lognot

Returns the bitwise not of its integer argument.

285

logbit?

Tests the value of a particular bit in its integer argument.

285

ash

Performs an arithmetic shift on its first argument.

286

Table 11-14 Methods on <integer>

Function

Description

Page

lcm

Returns the least common multiple of its two arguments.

286

gcd

Returns the greatest common divisor of its two arguments.

287

Table 11-15 Methods on singleton(<integer>)

Function

Description

Page

limited

Returns a limited subtype of a class.

263