Skip to main content

real

real System Class

Class Precedence List:

real, number, t

Description:

The type real includes all numbers that represent mathematical real numbers, though there are mathematical real numbers (e.g., irrational numbers) that do not have an exact representation in Common Lisp. Only reals can be ordered using the <, >, <=, and >= functions.

The types rational and float are disjoint subtypes of type real.

Compound Type Specifier Kind:

Abbreviating.

Compound Type Specifier Syntax:

(real [lower-limit [upper-limit]])

Compound Type Specifier Arguments:

lower-limit, upper-limitinterval designators for type real. The defaults for each of lower-limit and upper-limit is the symbol *.

Compound Type Specifier Description:

This denotes the reals on the interval described by lower-limit and upper-limit.

Expanded Reference: real

Type Checking

The real type includes all numbers that can be placed on the number line: integers, ratios, and floats. Complex numbers are not real.

(typep 42 'real)
=> T
(typep 3.14 'real)
=> T
(typep 2/3 'real)
=> T
(typep #C(1 2) 'real)
=> NIL
(realp 42)
=> T
(realp #C(1 2))
=> NIL

Type Hierarchy

The real type has two subtypes: rational and float. It is itself a subtype of number.

(subtypep 'rational 'real)
=> T
=> T
(subtypep 'float 'real)
=> T
=> T
(subtypep 'integer 'real)
=> T
=> T
(subtypep 'real 'number)
=> T
=> T
(subtypep 'complex 'real)
=> NIL
=> T

Type Specifier with Range

The real type specifier accepts optional lower and upper bounds, covering all real subtypes.

(typep 0.5 '(real 0 1))
=> T
(typep 1/2 '(real 0 1))
=> T
(typep 1 '(real 0 1))
=> T
(typep 1.5 '(real 0 1))
=> NIL
(typep -1 '(real 0 *))
=> NIL

Ordering Operations

Real numbers support the ordering operations <, >, <=, >=, which are not available for complex numbers.

(< 1 1.5 2/1 3)
=> T
(min 1 0.5 3/2)
=> 0.5
(max 1 0.5 3/2)
=> 3/2

;; Real numbers can be compared across types
(<= 0 1/3 0.5 1)
=> T