The fixed Reference Manual

This is the fixed Reference Manual, version 0.0.2, generated automatically by Declt version 4.0 beta 2 "William Riker" on Wed May 15 05:14:39 2024 GMT+0.

Table of Contents


1 Introduction


2 Systems

The main system appears first, followed by any subsystem dependency.


2.1 fixed

A fixed-point number type.

Author

Nick Patrick <>

License

MIT

Version

0.0.2

Source

fixed.asd.

Child Component

src (module).


3 Modules

Modules are listed depth-first from the system components tree.


3.1 fixed/src

Source

fixed.asd.

Parent Component

fixed (system).

Child Components

4 Files

Files are sorted by type and then listed depth-first from the systems components trees.


4.1 Lisp


4.1.1 fixed/fixed.asd

Source

fixed.asd.

Parent Component

fixed (system).

ASDF Systems

fixed.


4.1.2 fixed/src/package.lisp

Source

fixed.asd.

Parent Component

src (module).

Packages

fixed.


4.1.3 fixed/src/reader.lisp

Source

fixed.asd.

Parent Component

src (module).

Public Interface
Internals

4.1.4 fixed/src/fixed.lisp

Source

fixed.asd.

Parent Component

src (module).

Public Interface
Internals

5 Packages

Packages are listed by definition order.


5.1 fixed

Source

package.lisp.

Use List

common-lisp.

Public Interface
Internals

6 Definitions

Definitions are sorted by export status, category, package, and then by lexicographic order.


6.1 Public Interface


6.1.1 Special variables

Special Variable: *rounding-method*

#’round or #’truncate or similar functions will be used to handle precision loss.

Package

fixed.

Source

fixed.lisp.


6.1.2 Macros

Macro: defdecimal (name digits &key low high)

A short-cut for defining a base-10 decimal type, that also happens to be printed correctly.

Package

fixed.

Source

fixed.lisp.

Macro: defdelta (name delta &key low high small)

Define a fixed point class named NAME which supports a resolution
of DELTA. The class maintains the value as an
(INTEGER LOW-RANGE HIGH-RANGE) where the LOW-RANGE and HIGH_RANGE are determined to provide an engineering-unit value within the range of low to high.

When SMALL is provided, the resolution of the type is defined to
be exactly SMALL. When only DELTA is provided, the resolution of the type is defined to be the negative power of 2 that is no larger than DELTA.

e.g. (defdelta foo 1/10) yields a SMALL value of 1/16.
(defdelta foo 1/10 :small 1/10) yields a SMALL value of 1/10.

This definition also produces a set of related functions and generic methods for working with the NAME type.
- MAKE-NAME: Creates a NAME type with initial value rounded to the provided value.
- MAKE-NAME-VALUE: Creates a NAME type with internal value as provided.
- SET-NAME: A function to set the internal value according to the engineering unit value provided by rounding.
- SET-NAME-VALUE: A function to set the internal value.
- NAME-VALUE: Accessor (setf’able) for the internal value.
- NAME: Accessor (setf’able) for the engineering unit value.

- Predicates: f= f/= f< f<= f> f>=
- Math operations: f+ f- f* f/

Package

fixed.

Source

fixed.lisp.


6.1.3 Ordinary functions

Function: install-q-reader (&optional readtable)

The Q reader can be used to read fixed point types directly with
exact precision. Generic fixed point types will be read directly
as rational values, and are suitable as an argument for a compatible fixed point type using the MAKE-NAME constructor, where NAME is
the name of the fixed point type.

A generic ordinary fixed point Q spec looks like this:
#Q3 => a type with delta and small of (/ (expt 2 3))
#Q7.8 => a 16 bit (1+ 7 8) signed type with delta and small of (/ (expt 2 8))

A generic decimal fixed point Q spec looks like this:
#QD3 => a type with delta and small of 1/1000
#QD3.1 => a 5 bit type with delta and small of 1/10, i.e. min == -

Use the Q reader to input fixed-point literals in decimal form. The rightmost integer in the Q spec defines the number of fractional
bits. The left-most number before the period, if provided, defines
the number of non-fractional bits. The sign bit is implied.

e.g.
#Q3 1.5 => 3/2
#Q3 1.25 => 5/4
#Q3 1.125 => 9/8
#Q3 1.0625 => Error: 1.0625 is not a Q3

The error in the last one is because 1.0625 requires 4 fractional bits
to represent.

#Q4 1.0625 => 17/16

Currently, the reader function returns a ratio representing the
decimal value read.

Package

fixed.

Source

reader.lisp.


6.1.4 Generic functions

Generic Function: decimal-fixedp (object)

Is the object a decimal fixed point type.

Package

fixed.

Source

fixed.lisp.

Methods
Method: decimal-fixedp (object)
Method: decimal-fixedp ((object decimal-fp))
Generic Function: delta (fp)

Return the delta used by fp.

Package

fixed.

Source

fixed.lisp.

Generic Function: f* (value &rest rest)

Multiply all fixed-point arguments of a single
type. The first value returned is the resultant fixed-point value, the second value is the residual.

Package

fixed.

Source

fixed.lisp.

Generic Function: f+ (value &rest rest)

Sum all fixed-point arguments of a single type.

Package

fixed.

Source

fixed.lisp.

Generic Function: f- (value &rest rest)

Subtract all fixed-point arguments of a single type
from the first value when more than one value are provided. If only a single value is provided, negate that value.

Package

fixed.

Source

fixed.lisp.

Generic Function: f/ (value &rest rest)

Divide the first value by the rest, or perform the
inverse operation if a single value is provided.
The first value returned is the resultant fixed-point value, the second value is the residual.

Package

fixed.

Source

fixed.lisp.

Generic Function: f/= (number &rest rest)

Determine if fixed-point values of the same type are not equal.

Package

fixed.

Source

fixed.lisp.

Generic Function: f< (number &rest rest)

Determine if fixed-point values of the same type are in ascending order.

Package

fixed.

Source

fixed.lisp.

Generic Function: f<= (number &rest rest)

Determine if fixed-point values of the same type are in ascending-or-equal order.

Package

fixed.

Source

fixed.lisp.

Generic Function: f= (number &rest rest)

Determine if fixed-point values of the same type are equal.

Package

fixed.

Source

fixed.lisp.

Generic Function: f> (number &rest rest)

Determine if fixed-point values of the same type are in descending order.

Package

fixed.

Source

fixed.lisp.

Generic Function: f>= (number &rest rest)

Determine if fixed-point values of the same type are in descending-or-equal order.

Package

fixed.

Source

fixed.lisp.

Generic Function: fixedp (object)

Is the object an fixed point type.

Package

fixed.

Source

fixed.lisp.

Methods
Method: fixedp (object)
Method: fixedp ((object fp))
Generic Function: ordinary-fixedp (object)

Is the object an ordinary fixed point type.

Package

fixed.

Source

fixed.lisp.

Methods
Method: ordinary-fixedp (object)
Method: ordinary-fixedp ((object ordinary-fp))
Generic Function: ranged-fixedp (object)

Is the object a ranged fixed point type.

Package

fixed.

Source

fixed.lisp.

Methods
Method: ranged-fixedp (object)
Method: ranged-fixedp ((object ranged-fp))
Generic Function: size (fp)

Return the number of bits required by a ranged fp. An fp type defined with zero or one limits returns :INFINITY.

Package

fixed.

Source

fixed.lisp.

Generic Function: small (fp)

Return the scaling factor used by fp.

Package

fixed.

Source

fixed.lisp.


6.1.5 Standalone methods

Method: make-load-form ((fixed fp) &optional environment)
Source

fixed.lisp.


6.1.6 Conditions

Condition: q-reader-error
Package

fixed.

Source

reader.lisp.

Direct superclasses

error.

Direct subclasses
Condition: q-reader-invalid-value
Package

fixed.

Source

reader.lisp.

Direct superclasses

q-reader-error.

Direct methods

q-reader-invalid-value-message.

Direct slots
Slot: message
Initargs

:message

Readers

q-reader-invalid-value-message.

Writers

This slot is read-only.

Condition: q-reader-non-symbol
Package

fixed.

Source

reader.lisp.

Direct superclasses

q-reader-error.

Condition: q-reader-unknown-fixed-type
Package

fixed.

Source

reader.lisp.

Direct superclasses

q-reader-error.

Direct methods

unknown-fixed-type-symbol.

Direct slots
Slot: symbol
Package

common-lisp.

Initargs

:symbol

Readers

unknown-fixed-type-symbol.

Writers

This slot is read-only.


6.1.7 Classes

Class: fp
Package

fixed.

Source

fixed.lisp.

Direct subclasses
Direct methods
Direct slots
Slot: value
Class: ordinary-fp
Package

fixed.

Source

fixed.lisp.

Direct superclasses

fp.

Direct methods

ordinary-fixedp.


6.2 Internals


6.2.1 Constants

Constant: +whitespace+
Package

fixed.

Source

reader.lisp.


6.2.2 Macros

Macro: %defdelta (name delta low high small super)

Do the work of creating the delta type.

Package

fixed.

Source

fixed.lisp.

Macro: make-q-class (pwr)
Package

fixed.

Source

fixed.lisp.

Macro: math (mname name sv-name v-name fn)
Package

fixed.

Source

fixed.lisp.

Macro: predicate (pname name raw fn)
Package

fixed.

Source

fixed.lisp.


6.2.3 Ordinary functions

Function: clear-whitespace (stream)
Package

fixed.

Source

reader.lisp.

Function: pwr-of-2? (number)

Is a number a power of 2? If so, return that power.

Package

fixed.

Source

fixed.lisp.

Function: q-class-name (pwr &optional bits)
Package

fixed.

Source

fixed.lisp.

Function: q-ratio (value sizes)
Package

fixed.

Source

reader.lisp.

Function: q-reader (stream subchar arg)

A generic Q spec looks like this:

#Q3 => a type with delta and small of (/ (expt 2 3))
Return value (cons nil 3)

#Q7.8 => a 16 bit (1+ 7 8) signed type with delta and small of (/ (expt 2 8)) Return value (cons 7 8)

Alternatively, a generic Q spec could be in decimal form:

#QD2 123.45 => 12345/100

Package

fixed.

Source

reader.lisp.

Function: ratio-meets-spec? (raw spec)
Package

fixed.

Source

reader.lisp.

Function: read-decimal-q (stream)

Read a decimal #QD with infinite precision, or #QDvalue where value is some integer defining the number of digits of precision.

Package

fixed.

Source

reader.lisp.

Function: read-decimal-q-decimal (stream spec spec-sizes)

Read a decimal #QD with infinite precision, or #QDvalue where value is some integer defining the number of digits of precision.

Package

fixed.

Source

reader.lisp.

Function: read-integer (stream &optional check-sign?)

Read a base-10 integer, leaving whitespace or other characters on the stream. The integer is terminated by any non-digit-char. Return is (values sign result power terminating-char)

Package

fixed.

Source

reader.lisp.

Function: read-ordinary-q (stream)

Read an ordinary fixed-point value.

Package

fixed.

Source

reader.lisp.

Function: read-ordinary-q-decimal (stream spec)

Read an ordinary fixed-point value.

Package

fixed.

Source

reader.lisp.

Function: read-q-character-spec (stream)

Read a user-specified Q type, or the D for a decimal type. If the first character read is #D or #d, followed by a digit character, then the result is ’D, indicating a decimal type.

Otherwise, the character is unread, the READ function is called, returning the resultant symbol

Package

fixed.

Source

reader.lisp.

Function: read-q-decimal (stream)

This reads the integer and fraction into the car and cdr of a cons. The second value is a cons of the count of digits in the first and second integers.

Package

fixed.

Source

reader.lisp.

Function: read-sign (stream)
Package

fixed.

Source

reader.lisp.

Function: read-user-decimal (decimal-type stream)
Package

fixed.

Source

reader.lisp.

Function: read-user-ordinary (ordinary-type stream)
Package

fixed.

Source

reader.lisp.

Function: spec-small (q-spec)

Given a cons of a Q spec (see Q-READER), return the inverse of the small-value of a corresponding fixed type.

Package

fixed.

Source

reader.lisp.

Function: symb (&rest strings)
Package

fixed.

Source

fixed.lisp.


6.2.4 Generic functions

Generic Reader: q-reader-invalid-value-message (condition)
Package

fixed.

Methods
Reader Method: q-reader-invalid-value-message ((condition q-reader-invalid-value))
Source

reader.lisp.

Target Slot

message.

Generic Reader: unknown-fixed-type-symbol (condition)
Package

fixed.

Methods
Reader Method: unknown-fixed-type-symbol ((condition q-reader-unknown-fixed-type))
Source

reader.lisp.

Target Slot

symbol.


6.2.5 Classes

Class: decimal-fp
Package

fixed.

Source

fixed.lisp.

Direct superclasses

fp.

Direct methods

decimal-fixedp.

Class: ranged-fp
Package

fixed.

Source

fixed.lisp.

Direct superclasses

fp.

Direct methods

ranged-fixedp.


Appendix A Indexes


A.1 Concepts


A.2 Functions

Jump to:   %  
C   D   F   G   I   M   O   P   Q   R   S   U  
Index Entry  Section

%
%defdelta: Private macros

C
clear-whitespace: Private ordinary functions

D
decimal-fixedp: Public generic functions
decimal-fixedp: Public generic functions
decimal-fixedp: Public generic functions
defdecimal: Public macros
defdelta: Public macros
delta: Public generic functions

F
f*: Public generic functions
f+: Public generic functions
f-: Public generic functions
f/: Public generic functions
f/=: Public generic functions
f<: Public generic functions
f<=: Public generic functions
f=: Public generic functions
f>: Public generic functions
f>=: Public generic functions
fixedp: Public generic functions
fixedp: Public generic functions
fixedp: Public generic functions
Function, clear-whitespace: Private ordinary functions
Function, install-q-reader: Public ordinary functions
Function, pwr-of-2?: Private ordinary functions
Function, q-class-name: Private ordinary functions
Function, q-ratio: Private ordinary functions
Function, q-reader: Private ordinary functions
Function, ratio-meets-spec?: Private ordinary functions
Function, read-decimal-q: Private ordinary functions
Function, read-decimal-q-decimal: Private ordinary functions
Function, read-integer: Private ordinary functions
Function, read-ordinary-q: Private ordinary functions
Function, read-ordinary-q-decimal: Private ordinary functions
Function, read-q-character-spec: Private ordinary functions
Function, read-q-decimal: Private ordinary functions
Function, read-sign: Private ordinary functions
Function, read-user-decimal: Private ordinary functions
Function, read-user-ordinary: Private ordinary functions
Function, spec-small: Private ordinary functions
Function, symb: Private ordinary functions

G
Generic Function, decimal-fixedp: Public generic functions
Generic Function, delta: Public generic functions
Generic Function, f*: Public generic functions
Generic Function, f+: Public generic functions
Generic Function, f-: Public generic functions
Generic Function, f/: Public generic functions
Generic Function, f/=: Public generic functions
Generic Function, f<: Public generic functions
Generic Function, f<=: Public generic functions
Generic Function, f=: Public generic functions
Generic Function, f>: Public generic functions
Generic Function, f>=: Public generic functions
Generic Function, fixedp: Public generic functions
Generic Function, ordinary-fixedp: Public generic functions
Generic Function, q-reader-invalid-value-message: Private generic functions
Generic Function, ranged-fixedp: Public generic functions
Generic Function, size: Public generic functions
Generic Function, small: Public generic functions
Generic Function, unknown-fixed-type-symbol: Private generic functions

I
install-q-reader: Public ordinary functions

M
Macro, %defdelta: Private macros
Macro, defdecimal: Public macros
Macro, defdelta: Public macros
Macro, make-q-class: Private macros
Macro, math: Private macros
Macro, predicate: Private macros
make-load-form: Public standalone methods
make-q-class: Private macros
math: Private macros
Method, decimal-fixedp: Public generic functions
Method, decimal-fixedp: Public generic functions
Method, fixedp: Public generic functions
Method, fixedp: Public generic functions
Method, make-load-form: Public standalone methods
Method, ordinary-fixedp: Public generic functions
Method, ordinary-fixedp: Public generic functions
Method, q-reader-invalid-value-message: Private generic functions
Method, ranged-fixedp: Public generic functions
Method, ranged-fixedp: Public generic functions
Method, unknown-fixed-type-symbol: Private generic functions

O
ordinary-fixedp: Public generic functions
ordinary-fixedp: Public generic functions
ordinary-fixedp: Public generic functions

P
predicate: Private macros
pwr-of-2?: Private ordinary functions

Q
q-class-name: Private ordinary functions
q-ratio: Private ordinary functions
q-reader: Private ordinary functions
q-reader-invalid-value-message: Private generic functions
q-reader-invalid-value-message: Private generic functions

R
ranged-fixedp: Public generic functions
ranged-fixedp: Public generic functions
ranged-fixedp: Public generic functions
ratio-meets-spec?: Private ordinary functions
read-decimal-q: Private ordinary functions
read-decimal-q-decimal: Private ordinary functions
read-integer: Private ordinary functions
read-ordinary-q: Private ordinary functions
read-ordinary-q-decimal: Private ordinary functions
read-q-character-spec: Private ordinary functions
read-q-decimal: Private ordinary functions
read-sign: Private ordinary functions
read-user-decimal: Private ordinary functions
read-user-ordinary: Private ordinary functions

S
size: Public generic functions
small: Public generic functions
spec-small: Private ordinary functions
symb: Private ordinary functions

U
unknown-fixed-type-symbol: Private generic functions
unknown-fixed-type-symbol: Private generic functions