1.4.5 Rational and Complex Arithmetic
Multiplies the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function
binary-*
Examples: |
> (*) | 1 | > (* 2) | 2 | > (* 1 2 3) | 6 |
|
Adds the given numbers together, taking any number of arguments. This is a macro that expands into calls of the function
binary-+.
Examples: |
> (+) | 0 | > (+ 2) | 2 | > (+ 1 2 3) | 6 |
|
Subtracts the given numbers. If only one argument is given, returns the negation of the input.
Divides the first number by the second. If only one argument is given, returns the reciprocal of the input.
Adds 1 to the given number.
Subtracts 1 from the given number.
Takes exactly two numbers and multiplies them together.
Takes exactly two numbers and adds them together.
Determines if the given numbers are not equal. Logically equivalent to
(not (equal x y))
Examples: |
> (/= 2 2) | '() | > (/= 3 2) | 't |
|
Determines if x is less than y.
Examples: |
> (< 1 2) | 't | > (< 2 1) | '() | > (< 2 2) | '() |
|
Determines if x is less than or equal to y.
Examples: |
> (<= 1 2) | 't | > (<= 2 1) | '() | > (<= 2 2) | 't |
|
Determines if
x is equal to
y. This is like
equal, but has the guard that both of its arguments must be numbers. It usually executes more efficiently thatn
equal.
Examples: |
> (= 1 2) | '() | > (= 2 1) | '() | > (= 2 2) | 't |
|
Determines if x is greater than y.
Examples: |
> (> 1 2) | '() | > (> 2 1) | 't | > (> 2 2) | '() |
|
Determines if x is greater than or equal to y.
Examples: |
> (>= 1 2) | '() | > (>= 2 1) | 't | > (>= 2 2) | 't |
|
Returns true if and only if x is a rational or complex rational number.
Determines if z is a complex number consisting of rational parts.
This is a test for the base case (zero) of recursion on the natural numbers.
Examples: |
> :eval | :eval: undefined; | cannot reference undefined identifier | > the-evaluator | the-evaluator: undefined; | cannot reference undefined identifier | > (zp 0) | zp: undefined; | cannot reference undefined identifier | > (zp 1) | zp: undefined; | cannot reference undefined identifier |
|
Determines whether x is a negative number.
Determines if x is a natural number.
Determines if x is odd.
Determines if x is positive.
Determines if x is a positive integer.
Determines if x is a rational number.
In most cases, this is just a macro abbreviating
rationalp.
Computes the absolute value of x.
Returns the smallest integer greater the value of
(/ i j).
Creates a complex number with real part n and imaginary part i.
Computes the complex conjugate of x (the result of negating its imaginary part).
Returns the divisor of a rational number in lowest terms.
Determines if x is even.
Returns a list of characters representing n in base-r, and appends l to the end.
Raises i to the jth power.
Coerces
x to a number. If
x is a number,
(fix x) returns the argument unchanged. Otherwise, it returns 0.
Returns the greatest integer not exceeding the value of
(/ i j).
Coerces
x to an integer. If
x is an integer,
(ifix x) returns the argument unchanged. Otherwise, it returns 0.
Returns the imaginary part of a complex number.
Checks to see if the two integers
i and
j are equal. This is like
equal and
=, but with the added guard that the inputs are integers. This generally executes more efficiently on integers than
equal or
=.
Returns the number of bits in the two’s complement binary representation of x.
Determines whether x is an integer.
Returns the greater of the two given numbers.
Returns the lesser of the two given numbers.
Computes the remainder of dividing i by j.
Coerces
x to a natural number. If
x is a natural number,
(nfix x) returns the argument unchanged. Otherwise, it returns 0.
Returns the integer quotient of
x and
y. That is,
(nonnegative-integer-quotient x y) is the largest integer
k such that
(* j k) is less than or equal to
x.
Returns the dividend of a rational number in lowest terms.
Coerces
x to a real number. If
x satisfies
(real/rationalp x), then it returns the argument unchanged. Otherwise, returns 0.
Returns the real part of a complex number.
Calculates the remainder of
(/ i j) using
truncate.
Coerces x into a rational number. If x is a rational number, then it returns x unchanged. Otherwise, it returns 0.
Rounds
(/ i j) to the nearest integer. When the quotient is exactly halfway between to integers, it rounds to the even one.
Returns 0 if x is 0, -1 if it is negative, and 1 if it is positive.
Computes
(/ i j) and rounds down to the nearest integer.
Computes the negative of the input.
Computes the reciprocal of the input.