[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FIXing functions



(In the following note, I will let "FX" mean "any one of
FLOOR, CEIL, TRUNC, or ROUND".)

I strongly support the idea that the FIXing functions
return two values: quotient and remainder.  These are not hard
to compile if they are appropriately special-cased.
The compiler can easily tell what is going on in such
situations as:
	(FX Z)
	(FX Z Y)
	(MULTIPLE-VALUE (Q R) (FX Z))
	(MULTIPLE-VALUE (() R) (FX Z))		;i.e., MOD or REMAINDER
and generate appropriate code for each.

To be more precise, it seems to me that the type of the second result
should be floating if either argument is, and an integer if both
arguments are integers.  Also, the one-argument case is exactly the same
as specifying a second argument of 1; hence an appropriate
description of the function is (DEFUN FX (X &OPTIONAL (Y 1)) ...).
Finally, the results Q and R are such that X=Q*Y+R, modulo any
floating-point inaccuracies.

Hence we have the following examples:
		Results
Argument(s)	FLOOR		CEIL		TRUNC		ROUND
4.5		4  0.5		5  -0.5		4  0.5		4  0.5
4.5  2		2  0.5		3  -0.5		2  0.5		2  0.5
7.0  2		3  1.0		4  -1.0		3  1.0		4  -1.0
7  2		3  1		4  -1		3  1		4  -1
7  2.3		3  0.1		4  -2.2		3  0.1		3  0.1
7.5  2.3	3  0.6		4  -1.7		3  0.6		3  0.6
9		9  0		9  0		9  0		9  0
Implementationally it is convenient to break this down into a number
of cases.  Semantically I believe this is the most useful definition.

--Guy