Common Lisp Package: CL-NUM-UTILS.NUM=

README:

FUNCTION

Public

NUM-DELTA (A B)

|a-b|/max(1,|a|,|b|). Useful for comparing numbers.

NUM=-FUNCTION (TOLERANCE)

Curried version of num=, with given tolerance.

MACRO

Public

DEFINE-NUM=-WITH-ACCESSORS (CLASS ACCESSORS)

Define a method for NUM=, specialized to the given class, comparing values obtained with accessors.

DEFINE-STRUCTURE-NUM= (STRUCTURE &REST SLOTS)

Define a NUM= method for the given structure, comparing the given slots.

GENERIC-FUNCTION

Public

NUM= (A B &OPTIONAL TOLERANCE)

Compare A and B for approximate equality, checking corresponding elements when applicable (using TOLERANCE). Two numbers A and B are NUM= iff |a-b|/max(1,|a|,|b|) <= tolerance. Unless a method is defined for them, two objects are compared with EQUALP. Generally, methods should be defined so that two objects are NUM= if they the same class, same dimensions, and all their elements are NUM=.

VARIABLE

Public

*NUM=-TOLERANCE*

Default tolerance for NUM=.