Node:Quantities, Next:, Previous:Procedures, Up:Extensions



Quantities and Numbers

As a super-class of numbers, Kawa also provides quantities. A quantity is a product of a unit and a pure number. The number part can be an arbitrary complex number. The unit is a product of integer powers of base units, such as meter or second.

Kawa quantities are a generalization of the quantities in DSSSL, which only has length-derived quantities.

The precise syntax of quantity literals may change, but some examples are 10pt (10 points), 5s (5 seconds), and 4cm^2 (4 square centimeters).

quantity? object Function
True iff object is a quantity. Note that all numbers are quantities, but not the other way round. Currently, there are no quantities that re not numbers. To distinguish a plain unit-less number from a quantity, you can use complex?.

quantity->number q Function
Returns the pure number part of the quantity q, relative to primitive (base) units. If q is a number, returns q. If q is a unit, yields the magitude of q relative to base units.

quantity->unit q Function
Returns the unit of the quantity q. If q is a number, returns the empty unit.

make-quantity x unit Function
Returns the product of x (a pure number) and unit. You can specify a string instead of unit, such as "cm" or "s" (seconds).

define-base-unit unit-name dimension Syntax
Define unit-name as a base (primitive) unit, which is used to measure along the specified dimension.
          (define-base-unit dollar "Money")
          

define-unit unit-name expression Syntax
Define unit-name as a unit (that can be used in literals) equal to the quantity expression.
          (define-unit cent 0.01dollar)
          

quotient x y Function
Generalized to arbitrary real numbers, using the definition: (truncate (/ x y)).

remainder x y Function
Generalized to arbitrary real numbers, using the definition: (- x (* y (truncate (/ x y)))). If y is 0, the result is x - i.e. we take (* 0 (quotient x 0)) to be 0. The result is inexact if either argument is inexact, even if x is exact and y is 0.

modulo x y Function
Generalized to arbitrary real numbers, using the definition: (- x (* y (floor (/ x y)))). If y is 0, the result is x. The result is inexact if either argument is inexact, even if x is exact and y is 0.