5.1.7 Arithmetic

Integer-Length (Object)

returns the integer-length (as defined in the Common Lisp manual) of the integer Object.

Logcount (Object)

returns the number of 1’s if object is a positive integer, the number of 0’s if object is a negative integer, and signals an error otherwise.

Float-Short (Object)

returns a short-float corresponding to the number Object.

Float-Long (Number)

returns a long float formed by coercing Number to a long float. This corresponds to the Common Lisp function Float when given a long float as its second argument.

Realpart (Number)

returns the realpart of the Number.

Imagpart (Number)

returns the imagpart of the Number.

Numerator (Number)

returns the numerator of the rational Number.

Denominator (Number)

returns the denominator of the rational Number.

Decode-Float (Number)

performs the Common Lisp Decode-Float function, returning 3 values.

Scale-Float (Number X)

performs the Common Lisp Scale-Float function, returning the result.

= (X Y)

sets the condition codes according to whether X is equal to Y. Both X and Y must be numbers, otherwise an error is signalled. If a rational is compared with a flonum, the rational is converted to a flonum of the same type first. If a short flonum is compared with a long flonum, the short flonum is converted to a long flonum. Flonums must be exactly equal (after conversion) for the condition codes to be set to equality. This miscop also deals with complex numbers.

Compare (X Y)

sets the condition codes according to whether X is less than, equal to, or greater than Y. X and Y must be numbers. Conversions as described in = above are done as necessary. This miscop replaces the < and > instructions on the Perq, so that the branch on condition instructions can be used more effectively. The value of < and > as defined for the Perq are only generated if necessary, i.e., the result is saved. If X or Y is a complex number, an error is signalled.

Truncate (N X)

performs the Common Lisp TRUNCATE operation. There are 3 cases depending on X:

  • If X is fixnum 1, return two items: a fixnum or bignum representing the integer part of N (rounded toward 0), then either 0 if N was already an integer or the fractional part of N represented as a flonum or ratio with the same type as N.
  • If X and N are both fixnums or bignums and X is not 1, divide N by X. Return two items: the integer quotient (a fixnum or bignum) and the integer remainder.
  • If either X or N is a flonum or ratio, return a fixnum or bignum quotient (the true quotient rounded toward 0), then a flonum or ratio remainder. The type of the remainder is determined by the same type-coercion rules as for +. The value of the remainder is equal to N - X * Quotient.

On the IBM RT PC, the integer part is returned in register A0, and the remainder in A1.

+, -, *, / (N X)

returns N + X. -, *, and / are similar.

Fixnum*Fixnum, Fixnum/Fixnum (N X)

returns N * X, where both N and X are fixnums. Fixnum/ is similar.

1+ (E)

returns E + 1.

1- (E)

returns E - 1.

Negate (N)

returns -N.

Abs (N)

returns |N|.

GCD (N X)

returns the greatest common divisor of the integers N and X.

Logand (N X)

returns the bitwise and of the integers N and X. Logior and Logxor are analogous.

Lognot (N)

returns the bitwise complement of N.

Boole (Op X Y)

performs the Common Lisp Boole operation Op on X, and Y. The Boole constants for CMU Common Lisp are these:

	boole-clr	0
	boole-set	1
	boole-1 	2
	boole-2 	3
	boole-c1	4
	boole-c2	5
	boole-and	6
	boole-ior	7
	boole-xor	8
	boole-eqv	9
	boole-nand	10
	boole-nor	11
	boole-andc1	12
	boole-andc2	13
	boole-orc1	14
	boole-orc2	15
Ash (N X)

performs the Common Lisp ASH operation on N and X.

Ldb (S P N)

All args are integers; S and P are non-negative. Performs the Common Lisp LDB operation with S and P being the size and position of the byte specifier.

Mask-Field (S P N)

performs the Common Lisp Mask-Field operation with S and P being the size and position of the byte specifier.

Dpb (V S P N)

performs the Common Lisp DPB operation with S and P being the size and position of the byte specifier.

Deposit-Field (V S P N)

performs the Common Lisp Deposit-Field operation with S and P as the size and position of the byte specifier.

Lsh (N X)

returns a fixnum that is N shifted left by X bits, with 0’s shifted in on the right. If X is negative, N is shifted to the right with 0’s coming in on the left. Both N and X should be fixnums.

Logldb (S P N)

All args are fixnums. S and P specify a “byte” or bit-field of any length within N. This is extracted and is returned right-justified as a fixnum. S is the length of the field in bits; P is the number of bits from the right of N to the beginning of the specified field. P = 0 means that the field starts at bit 0 of N, and so on. It is an error if the specified field is not entirely within the 26 bits of N

Logdpb (V S P N)

All args are fixnums. Returns a number equal to N, but with the field specified by P and S replaced by the S low-order bits of V. It is an error if the field does not fit into the 26 bits of N.

Sin(X), Cos(X), Tan(X), and Atan(X)

accept a single number X as argument and return the sine, cosine, tangent, and arctangent of the number respectively. These miscops take advantage of the hardware support provided on the IBM RT PC if it is available, otherwise they escape to Lisp code to calculate the appropriate result.

Log(X)

returns the natural log of the number X. This miscop uses the hardware operation if it is available, otherwise it escapes to Lisp code to calculate the result.

Exp(X)

returns e raised to the power X. This miscop uses the hardware operation if it is available, otherwise it escapes to Lisp code to calculate the result.

Sqrt(X)

returns the square root of X. This miscop uses the hardware operation if it is available, otherwise it escapes to Lisp code to calculate the result.