 # Arithmetic Functions Scheme's arithmetic functions are extended slightly, to include some operations common in computer vision and geometrical algorithms.

Notice that various special restrictions on numerical types and operations apply within user-defined coprocessor functions. For example, the function = cannot be applied to inexact numbers or points.

### Missing values

Many functions can return a missing value if a numerical, boolean, or point value is unavailable.

Also, certain standard mathematical functions are only partial, i.e. not defined for some possible input values. These functions return a missing value for the bad inputs, rather than triggering an error break. Examples include atan (binary version only), log, sqrt, asin, acos, random-real, expt, /, remainder, quotient, and modulo.

### Random number generation

The function (random-real x y) takes two real inputs x and y, and returns a randomly generated real number in the range [x,y). This generator is randomly initialized.

### Trigonometry

The symbol pi is bound to the well-known constant.

### Bitwise operations

The following operations are required for manipulating images whose values are bit-vectors, such as certain edge maps. The function names follow those in Scheme48's "big scheme."

• (bitwise-not integer)
• (bitwise-and integer integer)
• (bitwise-ior integer integer)
• (bitwise-xor integer integer)
• (arithmetic-shift integer n) shifts the integer n bits (positive means left)

### Vector operations

The functions +, -, *, =, round, exact?, inexact?, inexact->exact, exact->inexact, zero?, integer? and real? can be applied to points of any dimension, not just numbers. The usual numerical operation is applied component-wise. One (but not more than one) of the inputs to * can be a point of dimension larger than 1. The first input to / can be a point of dimension larger than 1.

The following modular arithmetic operations are added (integer inputs only):

• evenly-divides?: returns a boolean
• even-quotient: solves the equation P = a*Q, where P is the first input and the second input is either a or Q. (That is, the inputs must have the same dimension or the second input must be a scalar.)

Even-quotient returns a missing value if the first input is not an even multiple of the second.

Also, the following vector operations are added

• (vector-magnitude point) computes the standard Euclidean (root sum of squares) distance.
• (cross-product point1 point2) computes the cross product of two 3D points
• (dot-product point1 point2) computes the dot product of two points of any dimension. The output is a number.

The usual rules of floating point contagion apply.

Notice that vector-magnitude is the same as abs when applied to a 1D point (number). Similarly, the dot-product of two numbers is their product.

It may seem tempting to generalize modular arithmetic operations (quotient, remainder, modulo) to vectors. However, it is not clear how to define their output when the remainder has both negative and positive components. Similar difficulties apply to negative? and positive?. These problems result from the fundamental fact that there is one obvious ordering on the real numbers (up to sign) but multiple reasonable ways to order points in 2D and 3D. 