> For the complete documentation index, see [llms.txt](https://www.lisppad.app/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.lisppad.app/libraries/lispkit/lispkit-math-util.md).

# (lispkit math util)

Library `(lispkit math util)` implements mathematical utility functions.

***

**(sgn&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Implements the sign/signum function. Returns -1 if *x* is negative, 0 (or a signed zero, when inexact) if *x* is zero, and 1 if *x* is a positive number. `sgn` fails if *x* is not a real number.

**(numbers&#x20;*****lo hi*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">\
\&#xNAN;**(numbers&#x20;*****lo hi f*****)**\
\&#xNAN;**(numbers&#x20;*****lo hi guard f*****)**

Returns a list of numbers by iterating from integer *lo* to integer *hi* (both inclusive) and applying function *f* to each integer in the range for which *guard* returns true. The default guard always returns true. The default for *f* is `identity`.

**(sum&#x20;*****xs*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the sum of all numbers of list *xs*. This procedure fails if there is an element in *xs* which is not a number.

**(product&#x20;*****xs*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the product of all numbers of list *xs*. This procedure fails if there is an element in *xs* which is not a number.

**(minimum&#x20;*****xs*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the minimum of all numbers of list *xs*. This procedure fails if there is an element in *xs* which is not a number.

**(maximum&#x20;*****xs*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the maximum of all numbers of list *xs*. This procedure fails if there is an element in *xs* which is not a number.

**(conjugate&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Conjugates number *x*. For real numbers *x*, `conjugate` returns *x*, otherwise *x* is being returned with the opposite sign for the imaginary part.

**(degrees->radians&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Converts degrees into radians.

**(radians->degrees&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Converts radians into degrees.

**(prime?&#x20;*****n*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if integer *n* is a prime number, `#f` otherwise.

**(make-nan&#x20;*****neg quiet payload*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns a NaN whose sign bit is equal to *neg* (`#t` for negative, `#f` for positive), whose quiet bit is equal to *quiet* (`#t` for quiet, `#f` for signaling), and whose payload is the positive exact integer *payload*. It is an error if *payload* is larger than a NaN can hold.

**(nan-negative?&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if the sign bit of *x* is 1 and `#f` otherwise.

**(nan-quiet?&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if *x* is a quiet NaN.

**(nan-payload&#x20;*****x*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns the payload bits of floating-point number *x* as a positive exact integer.

**(nan=?&#x20;*****x y*****)** <img src="/files/STqjiJsrexexyFklGQwH" alt="" data-size="line">

Returns `#t` if *x* and *y* have the same sign, quiet bit, and payload; and `#f` otherwise.
