Chapter 12
The Built-In Functions
Arithmetic Operations
Properties
odd?
[Function]
Tests for the property of being an odd number.
- Signature:
-
odd? integer
⇒boolean
- Arguments:
-
- integer
-
An instance of
<integer>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
Returns true if its argument is an odd number.
even?
[Function]
Tests for the property of being an even number.
- Signature:
-
even? integer
⇒boolean
- Arguments:
-
- integer
-
An instance of
<integer>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
Returns true if its argument is an even number.
zero?
[Open Generic Function]
Tests for the property of being equal to zero.
- Signature:
-
zero? object
⇒boolean
- Arguments:
-
- object
-
An instance of
<object>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
-
Returns true if its argument is equal to zero.
zero? complex
⇒boolean
[Sealed G.F. Method]A method is defined for the class
<complex>
.
positive?
[Open Generic Function]
Tests for the property of being positive.
- Signature:
-
positive? object
⇒boolean
- Arguments:
-
- object
-
An instance of
<object>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
-
Returns true if its argument is positive.
positive? real
⇒boolean
[Sealed G.F. Method]A method is defined for the class
<real>
.
negative?
[Open Generic Function]
Tests for the property of being negative.
- Signature:
-
negative? object
⇒boolean
- Arguments:
-
- object
-
An instance of
<object>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
-
Returns true if its argument is negative.
negative? real
⇒boolean
[Sealed G.F. Method]A method is defined for the class
<real>
.
integral?
[Open Generic Function]
Tests for the property of being integral.
- Signature:
-
integral? object
⇒boolean
- Arguments:
-
- object
-
An instance of
<object>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
Returns true if its argument is an integer.
integral? object
⇒false
[G.F. Method]A method is defined for the class
<object>
that returns#f
.integral? real
⇒boolean
[Sealed G.F. Method]A method is defined for real numbers that is equivalent to
real = round(real)
.
Arithmetic Operations
+
[Open Generic Function]
Returns the sum of its arguments.
- Signature:
-
object1 + object2
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Adds two objects and returns the sum.
complex1 + complex2
⇒complex
[Sealed G.F. Method]A predefined method returns the sum of two complex numbers.
*
[Open Generic Function]
Returns the product of its arguments.
- Signature:
-
object1 * object2
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Multiplies two objects and returns the product.
complex1 * complex2
⇒complex
[Sealed G.F. Method]A predefined method returns the product of two complex numbers.
-
[Open Generic Function]
Returns the difference of its arguments.
- Signature:
-
object1 - object2
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Subtracts object2 from object1 and returns the difference.
complex1 - complex2
⇒complex
[Sealed G.F. Method]A predefined method returns the difference of two complex numbers.
/
[Open Generic Function]
Returns the quotient of its arguments.
- Signature:
-
object1 / object2
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Divides object2 into object1 and returns the quotient.
complex1 / complex2
⇒complex
[Sealed G.F. Method]A predefined method returns the quotient of two complex numbers.
negative
[Open Generic Function]
Returns the negation of an object.
- Signature:
-
negative object1
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Returns the negation of its argument. The unary minus operator is equivalent to a call to the
negative
in the current binding environment.negative real1
⇒real2
[Sealed G.F. Method]A predefined method returns the additive inverse of a real number.
floor
[Function]
Truncates a real number toward negative infinity.
- Signature:
-
floor real1
⇒integer real2
- Arguments:
-
- real1
-
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real2
An instance of
<real>
.
- Description:
-
Truncates real1 toward negative infinity. The integer part is returned as integer, the remainder is returned as real2.
ceiling
[Function]
Truncates a real number toward positive infinity.
- Signature:
-
ceiling real1
⇒integer real2
- Arguments:
-
- real1
-
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real2
An instance of
<real>
.
- Description:
Truncates real1 toward positive infinity. The integer part is returned as integer, the remainder is returned as real2.
round
[Function]
Rounds a real number toward the nearest mathematical integer.
- Signature:
-
round real1
⇒integer real2
- Arguments:
-
- real1
-
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real2
An instance of
<real>
.
- Description:
Rounds real1 toward the nearest mathematical integer. The integer part is returned as integer, the remainder is returned as real2. If real1 is exactly between two integers, then the result integer will be a multiple of two.
truncate
[Function]
Truncates a real number toward zero.
- Signature:
-
truncate real1
⇒integer real2
- Arguments:
-
- real1
-
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real2
An instance of
<real>
.
- Description:
Truncates real1 toward zero. The integer part is returned as integer, the remainder is returned as real2.
floor/
[Function]
Returns the floor of the quotient of two numbers.
- Signature:
-
floor/ real1 real2
⇒integer real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real3
An instance of
<real>
.
- Description:
Divides real2 into real1 and truncates the result toward negative infinity. The integer part of the result is returned as integer, the remainder is returned as real3.
ceiling/
[Function]
Returns the ceiling of the quotient of two numbers.
- Signature:
-
ceiling/ real1 real2
⇒integer real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real3
An instance of
<real>
.
- Description:
Divides real2 into real1 and truncates the result toward positive infinity. The integer part of the result is returned as integer, the remainder is returned as real3.
round/
[Function]
Rounds off the quotient of two numbers.
- Signature:
-
round/ real1 real2
⇒integer real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real3
An instance of
<real>
.
- Description:
Divides real2 into real1 and rounds the result toward the nearest mathematical integer. The integer part of the result is returned as integer, the remainder is returned as real3. If the result of the division is exactly between two integers, then the result integer will be a multiple of two.
truncate/
[Function]
Returns the truncated quotient of two numbers.
- Signature:
-
truncate/ real1 real2
⇒integer real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- integer
-
An instance of
<integer>
. - real3
An instance of
<real>
.
- Description:
Divides real2 into real1 and truncates the result toward zero. The integer part of the result is returned as integer, the remainder is returned as real3.
modulo
[Function]
Returns the second value
of floor/
.
- Signature:
-
modulo real1 real2
⇒real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- real3
-
An instance of
<real>
.
- Description:
Returns the second value of
floor/(real1, real2)
.
remainder
[Function]
Returns the second value
of truncate/
.
- Signature:
-
remainder real1 real2
⇒real3
- Arguments:
-
- real1
-
An instance of
<real>
. - real2
An instance of
<real>
.
- Values:
-
- real3
-
An instance of
<real>
.
- Description:
Returns the second value of
truncate/(real1, real2)
.
^
[Open Generic Function]
Raises an object to a specified power.
- Signature:
-
object1 ^ object2
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Returns object1 raised to the power object2. An error is signaled if both arguments are zero.
complex ^ integer
⇒number
[Sealed G.F. Method]A predefined method raises a complex number to an integral power and returns the result.
abs
[Open Generic Function]
Returns the absolute value of its argument.
- Signature:
-
abs object1
⇒#rest objects
- Arguments:
-
- object1
-
An instance of
<object>
.
- Values:
-
- objects
-
Instances of
<object>
.
- Description:
-
Returns the absolute value of object1.
abs complex
⇒real
[Sealed G.F. Method]A predefined method returns the absolute value of a complex number.
logior
[Function]
Returns the bitwise inclusive or of its integer arguments.
- Signature:
-
logior #rest integers
⇒integer
- Arguments:
-
- integers
-
Zero or more instances of
<integer>
.
- Values:
-
- integer
-
An instance of
<integer>
.
- Description:
Returns the bitwise inclusive or of the integers.
logxor
[Function]
Returns the bitwise exclusive or of its integer arguments.
- Signature:
-
logxor #rest integers
⇒integer
- Arguments:
-
- integers
-
Zero or more instances of
<integer>
.
- Values:
-
- integer
-
An instance of
<integer>
.
- Description:
Returns the bitwise exclusive or of the integers.
logand
[Function]
Returns the bitwise and of its integer arguments.
- Signature:
-
logand #rest integers
⇒integer
- Arguments:
-
- integers
-
Zero or more instances of
<integer>
.
- Values:
-
- integer
-
An instance of
<integer>
.
- Description:
Returns the bitwise and of the integers.
lognot
[Function]
Returns the bitwise not of its integer argument.
- Signature:
-
lognot integer1
⇒integer2
- Arguments:
-
- integer1
-
An instance of
<integer>
.
- Values:
-
- integer2
-
An instance of
<integer>
.
- Description:
Returns the bitwise not of the integer1.
logbit?
[Function]
Tests the value of a particular bit in its integer argument.
- Signature:
-
logbit? index integer
⇒boolean
- Arguments:
-
- index
-
An instance of
<integer>
. - integer
An instance of
<integer>
.
- Values:
-
- boolean
-
An instance of
<boolean>
.
- Description:
-
Returns true if the indexth bit in integer is a one-bit; otherwise it returns false.
Negative integers are treated as if they were in two's-complement notation.
ash
[Function]
Performs an arithmetic shift on its first argument.
- Signature:
-
ash integer1 count
⇒integer2
- Arguments:
-
- integer1
-
An instance of
<integer>.
- count
An instance of
<integer>.
- Values:
-
- integer2
-
An instance of
<integer>
.
- Description:
-
Performs an arithmetic shift on the binary representation of integer1.
ash
shifts integer1 arithmetically left by count bit positions if count is positive, or right count bit positions if count is negative. The shifted value of the same sign as integer1 is returned.When
ash
moves bits to the left, it adds zero-bits at the right. When it moves them to the right, it discards bits.ash
is defined to behave as if integer1 were represented in two's complement form, regardless of how integers are represented by the implementation.ash(8, 1) ⇒ 16 ash(32, -1) ⇒ 16
lcm
[Open Generic Function]
Returns the least common multiple of its two arguments.
- Signature:
-
lcm object1 object2
⇒object3
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- object3
-
An instance of
<object>
.
- Description:
-
Returns the least common multiple of object1 and object2.
lcm integer1 integer2
⇒integer3
[Sealed G.F. Method]A predefined method returns the least common multiple of two integers.
gcd
[Open Generic Function]
Returns the greatest common divisor of its two arguments.
- Signature:
-
gcd object1 object2
⇒object3
- Arguments:
-
- object1
-
An instance of
<object>
. - object2
An instance of
<object>
.
- Values:
-
- object3
-
An instance of
<object>
.
- Description:
-
Returns the greatest common divisor of object1 and object2.
gcd integer1 integer2
⇒integer3
[Sealed G.F. Method]A predefined method returns the greatest common divisor of two integers.