The expression language provides a quantity data type which represents
lengths and quantities derived from lengths,
such as areas and volumes.
The SI meter is used as the base unit for representing quantities.
The name of this unit is m.
Any quantity may be represented as the product of a number and
the base unit raised to the power of an integer.
The dimension of a quantity is the power to which the base unit
is raised when the quantity is so represented.
A quantity with dimension 0 is *dimensionless*.

[77] unit-declaration = (define-unit *unit-name* *expression*)

(define-unit cm 0.01m)

(define-unit mm 0.001m)

(define-unit in 0.0254m)

(define-unit pt 0.0003527778m)

(define-unit pica 0.004233333m)

(define-unit mm 0.001m)

(define-unit in 0.0254m)

(define-unit pt 0.0003527778m)

(define-unit pica 0.004233333m)

It is necessary to distinguish between quantities that are
represented exactly and those that may not be. For example, indexes
into data structures shall be known exactly.
In order to catch uses of inexact quantities where exact quantities are
required, the expression language explicitly distinguishes exact from inexact quantities.
This distinction is orthogonal to the dimension of type.

Implementations may also support only a limited range of numbers of
any type, subject to the requirements of this section. The supported
range for exact numbers of any type may be different from the
supported range for inexact numbers of that type. For example,
an implementation that uses floating point numbers to represent all its
inexact real numbers may
support a practically unbounded range of exact integers
while limiting the range of inexact reals (and, therefore,
the range of inexact integers)
to the dynamic range of the floating point format.
All implementations are required to support exact integers
between -2147483647 and 2147483647.

+ - *

quotient remainder modulo

max min abs

floor ceiling truncate

round expt

quotient remainder modulo

max min abs

floor ceiling truncate

round expt

[78] number = *num-2*
| *num-8*
| *num-10*
| *num-16*

[79] num-2 = #b *sign*? *digit-2*+

[80] num-8 = #o *sign*? *digit-8*+

[81] num-16 = #x *sign*? *digit-16*+

[82] num-10 = #d? *sign*? *decimal* *exponent*? *unit*?

[83] decimal = *digit-10*+
| . *digit-10*+
| *digit-10*+ . *digit-10**

[84] exponent = *exponent-marker* *sign*? *digit*+

[85] exponent-marker = e

[86] unit = *unit-name* (*sign*? *digit-10*+)?

[87] unit-name = *letter*+

[88] sign = + | -

[89] digit-2 = 0 | 1

[90] digit-8 = 0 | 1 | 2 | 3
| 4 | 5 | 6 | 7

[91] digit-10 = *digit*

[92] digit-16 = *digit-10*
| a | b | c | d | e | f

[93] digit = 0
| 1
| 2
| 3
| 4
| 5
| 6
| 7
| 8
| 9

A quantity may be written in binary, octal, decimal, or
hexadecimal by the use of a radix prefix. The radix prefixes are
#b (binary), #o (octal), #d (decimal),
and #x (hexadecimal). With
no radix prefix, a quantity is assumed to be expressed in decimal.

NOTE 15 |

The examples used in this section assume that any numerical constant written using an exact notation is indeed represented as an exact quantity. Some examples also assume that certain numerical constants written using an inexact notation may be represented without loss of accuracy; the inexact constants were chosen so that this is likely to be true in implementations that use floating point numbers to represent inexact quantities. |

(quantity? *obj*)

(number? *obj*)

(real? *obj*)

(integer? *obj*)

These type predicates may be applied to any kind of
argument, including non-quantities. They return #t if the object is
of the named type, and otherwise they return #f.
In general, if a type predicate is true of a quantity, then all higher
type predicates are also true of that quantity. Consequently, if a type
predicate is false for a quantity, then all lower type predicates are
also false for that quantity.

(real? 3) #t

(integer? 3.0) #t

(integer? 3.0) #t

NOTE 16 |

The behavior of these type predicates on inexact quantities is unreliable, since any inaccuracy may affect the result. |

(exact? *q*)

(inexact? *q*)

These numerical predicates provide tests for the exactness of a
quantity. For any quantity, precisely one of these predicates
is true.

(= *q1* *q2* *q3* )

(< *q1* *q2* *q3* )

(> *q1* *q2* *q3* )

(<= *q1* *q2* *q3* )

(>= *q1* *q2* *q3* )

These procedures return #t if their arguments are (respectively):
equal, monotonically increasing, monotonically decreasing,
monotonically nondecreasing, or monotonically nonincreasing.

NOTE 17 |

While it is not an error to compare inexact quantities using these predicates, the results may be unreliable because a small inaccuracy may affect the result; this is especially true of = and zero?. |

(zero? *q*)

(positive? *q*)

(negative? *q*)

(odd? *n*)

(even? *n*)

These predicates test a quantity for a particular property,
returning #t or #f. See note above.

(max *q1* *q2* )

(min *q1* *q2* )

These procedures return the maximum or minimum of their arguments.
The dimensions of all the arguments shall be identical;
the dimension of the result shall be the same as the dimension
of the arguments.

(max 3 4) 4 ; exact

(max 3.9 4) 4.0 ; inexact

(max 3.9 4) 4.0 ; inexact

NOTE 18 |

If any argument is inexact, then the result shall also be inexact (unless the procedure can prove that the inaccuracy is not large enough to affect the result, which is possible only in unusual implementations). If min or max is used to compare quantities of mixed exactness, and the numerical value of the result cannot be represented as an inexact quantity without loss of accuracy, then the procedure may report a violation of an implementation restriction. |

(+ *q1* )

Returns the sum of its arguments, which shall all have the same
dimension. The result shall have the same dimension as
the arguments.

(+ 3 4) 7

(+ 3) 3

(+) 0

(+ 3) 3

(+) 0

(* *q1* )

Returns the product of its arguments.
The dimension of the result shall
be the sum of the dimensions of the arguments.

(* 4) 4

(*) 1

(*) 1

(- *q1* *q2*)

(- *q*)

(- *q1* *q2* )

With two or more arguments, returns the difference of its arguments,
associating to the left; with one argument, returns the negation
of its argument.
The dimensions of all the arguments shall be identical.
The dimension of the result shall be the same as the dimension
of the arguments.

(- 3 4) -1

(- 3 4 5) -6

(- 3) -3

(- 3 4 5) -6

(- 3) -3

(/ *q1* *q2*)

(/ *q*)

(/ *q1* *q2* )

With two or more arguments, returns the
quotient of its arguments, associating to the left; with one argument,
returns 1 divided by the argument.
The dimension of the result shall
be the difference of the dimensions of each of the arguments.

(/ 3 4 5) 3/20

(/ 3) 1/3

(/ 3) 1/3

(abs *q*)

Returns the magnitude of its argument.

(abs -7) 7

(quotient *n1* *n2*)

(remainder *n1* *n2*)

(modulo *n1* *n2*)

These procedures implement number-theoretic (integer)
division: For positive integers n1 and n2, if n3 and
n4 are integers such that
n1 = n2n3 +n4 and
0 n4 < n2, then the following is true.

(quotient n1 n2) n3

(remainder n1 n2) n4

(modulo n1 n2) n4

(remainder n1 n2) n4

(modulo n1 n2) n4

(= *n1* (+ (* *n2* (quotient *n1* *n2*))

(remainder*n1* *n2*)))

#t

(remainder

#t

(modulo 13 4) 1

(remainder 13 4) 1

(modulo -13 4) 3

(remainder -13 4) -1

(modulo 13 -4) -3

(remainder 13 -4) 1

(modulo -13 -4) -1

(remainder -13 -4) -1

(remainder -13 -4.0) -1.0 ; inexact

(remainder 13 4) 1

(modulo -13 4) 3

(remainder -13 4) -1

(modulo 13 -4) -3

(remainder 13 -4) 1

(modulo -13 -4) -1

(remainder -13 -4) -1

(remainder -13 -4.0) -1.0 ; inexact

(floor *x*)

(ceiling *x*)

(truncate *x*)

(round *x*)

These procedures return integers.

round rounds to even for consistency with the default rounding
mode specified by the IEEE floating point standard.

If the argument to one of these procedures is inexact, then the result
shall also be inexact. If an exact value is needed, the
result should be passed to the inexact->exact procedure.

(floor -4.3) -5.0

(ceiling -4.3) -4.0

(truncate -4.3) -4.0

(round -4.3) -4.0

(floor 3.5) 3.0

(ceiling 3.5) 4.0

(truncate 3.5) 3.0

(round 3.5) 4.0 ; inexact

(round 7) 7

(ceiling -4.3) -4.0

(truncate -4.3) -4.0

(round -4.3) -4.0

(floor 3.5) 3.0

(ceiling 3.5) 4.0

(truncate 3.5) 3.0

(round 3.5) 4.0 ; inexact

(round 7) 7

(exp *x*)

(log *x*)

Returns e raised to the power of *x*.
log computes the natural logarithm of *x*
(not the base-ten logarithm). If x is
zero or negative, an error shall be signaled.

(sin *x*)

(cos *x*)

(tan *x*)

sin, cos, and tan return the sine, cosine, and
tangent of their arguments, respectively.
The result shall be a number.

(asin *x*)

(acos *x*)

(atan *x*)

(atan *q1* *q2*)

asin, acos, and atan return
the arcsine, arccosine, and arctangent of their arguments,
respectively. The result shall be a number. The two-argument variant of atan returns the
angle of the complex number whose real part is the numerical value of
*q2* and whose imaginary part is the numerical value of
*q1*; the dimensions of *q1* and *q2* shall be
identical.

(sqrt *q*)

Returns the square root of *q*.
The dimension of *q* shall be even.
The dimension of the result shall
be half the dimension of *q*.
If *q* is negative, an error is signaled.

(expt *x1* *x2*)

Returns *x1* raised to the power *x2*.
(expt *x1* 0) is defined to be equal to 1.

(exact->inexact *q*)

(inexact->exact *q*)

Exact->inexact returns an inexact representation of *q*.
The value returned is the
inexact quantity that is numerically closest to the argument.
If an exact argument has no reasonably close inexact equivalent,
then a violation of an implementation restriction may be reported.

(quantity->number *q*)

Returns the number of the quantity *q*.

(number->string *number*)

(number->string *number* *radix*)

(let ((number *number*)

(radix*radix*))

(equal? number

(string->number (number->string number

radix)

radix)))

(radix

(equal? number

(string->number (number->string number

radix)

radix)))

NOTE 19 |

If number is an inexact number represented using floating-point
numbers, and
the radix is 10, then the above expression is normally satisfied by
a result containing a decimal point. The unspecified case
allows for infinities, NaNs, and non-floating-point representations. |

(format-number *n* *string*)

• 1 means use 0, 1, 2 |

• 01 means use 00, 01, 02, 10, 11 100, 101 and similarly for any number of leading zeros; |

• a means use 0, a, b, c, z, aa, ab, |

• A means use 0, A, B, C, Z, AA, AB, |

• i means use 0, i, ii, iii, iv, v, vi, vii, viii, ix, x, |

• I means use 0, I, II, III, IV, V, VI, VII, VIII, IX, X, |

(format-number-list *list* *obj1* *obj2*)

(string->number *string*)

(string->number *string* *radix*)

Returns a number of the maximally precise representation expressed by the
given *string*. *radix* shall be an exact integer, either 2, 8, 10,
or 16. If supplied, *radix* is a default radix that may be overridden
by an explicit radix prefix in *string* (e.g.,
"#o177"). If *radix*
is not supplied, then the default radix is 10. If *string* is not
a syntactically valid notation for a number, then string->number
returns #f.

(string->number "100") 100

(string->number "100" 16) 256

(string->number "1e2") 100.0

(string->number "100" 16) 256

(string->number "1e2") 100.0