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

Consing by ROUND, TRUNCATE, FLOOR, and CEILING



    Date: Mon, 25 Aug 86 14:15 CDT
    From: Wilson M. Michaels <mac@MCC.ARPA>

    I have been working with some graphics primatives that need to convert a
    ratio to a fixnum.   I discovered that ROUND, TRUNCATE, and FLOOR
    generate 3 words of structure consing while CEILING makes 9 words when 
    they are given a ratio as a single argument.    This generates lots of
    garbage.    Is there a function that will convert a ratio to a fixed
    number without all that garbage?

    Mac Michaels    <mac@mcc.com>

The structure being consed is the remainder (the second value returned).
If you don't care what the remainder is, you can do something like:

(defun rational-round-without-remainder (rational)
  (round (numerator rational) (denominator rational)))

- - -

(time (round 123/45) t)
Evaluation of (ROUND 41/15) took 0.001120 seconds of elapsed time
including 0.000 seconds waiting for the disk for 0 faults.
3 structure words consed in WORKING-STORAGE-AREA.
Consed in structure region of WORKING-STORAGE-AREA:  -4/15
3
-4/15

(time (rational-round-without-remainder 123/45) t)
Evaluation of (RATIONAL-ROUND-WITHOUT-REMAINDER 41/15) took 0.000737 seconds of elapsed time
including 0.000 seconds waiting for the disk for 0 faults.
There was no consing.
3
-4