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

Re: Query about proposed slight change to FIX and FIXR functions

[Why wasn't this just sent to LISP-FORUM??]

FIX isn't ridiculous -- it's just incompatible with FORTRAN
(but compatible with ALGOL and a few others).  WHat FIX should
do is very closely related to what integer division, remainder,
modulus, and arithmetic shift should do.  Think about it this way:
FIX divides the argument n by 1, producing integer quotient q and
a remainder r (which will be fractional); it then returns q.
If the remainder has the same sign as the dividend (true remainder),
then FIX rounds towards zero.  If it has the same sign as the divisor
(in this case, always positive), i.e., the remainder is actually a MOD
operation, then FIX rounds towards minus infinity.

Rather than change FIX incompatibly and potentially breaking programs,
I urge that the names FLOOR, CEILING, TRUNC, and ROUND be introduced,
to perform rounding towards minus infinity, plus infinity, zero,
and nearest integer, respectively.  I would be inclined simply not to guarantee
the behavior of ROUND on half-integers, leaving it to the implementation
to decide whether to round up or down; but I am not adamant on this point.

The point of these names is that various languages use the term FIX in
incompatible ways; but the four names proposed are never used for other
than the meanings I have described, and so leave the programmer in no
state of doubt as to what is going on.