Oct 24
Floating-point answer needed
This function is supposed to round a number to some given number of decimal places, returning a floating-point answer:
(DEFUN DECIMAL-PLACES (NUM PLACES)
(LET ((SCALE (EXPT 10 PLACES)))
(/ (ROUND (* NUM SCALE))
SCALE)))However, these results demonstrate that the present implementation isn’t returning floats:
(LIST (DECIMAL-PLACES 0.49 1)
(DECIMAL-PLACES 1 2)
(DECIMAL-PLACES 1/3 3))
=> (1/2 1 333/1000)
Filed under //
numbers
