While thinking about the way to implement Scheme R5RS, I have become puzzled about the following extract of R5RS (pages 22-23):
(remainder -13 -4) ==> -1
(remainder -13 -4.0) ==> -1.0 ; inexact(lcm 32 -36) ==> 288
(lcm 32.0 -36) ==> 288.0 ; inexact(denominator (/ 6 4)) ==> 2
(denominator (exact->inexact (/ 6 4))) ==> 2.0
Should we understand that, even if -4.0, 32.0 and (exact->inexact (/ 6 4)) are inexact, the implementation shall "remember" their exact equivalent (-4, 32 and 3/2) in order to proceed to integer division, prime factors decomposition, etc?
Otherwise, how could the implementation succeed in giving the above answers?
Thanks in advance for any light you could throw on this subject! :)
Nicolas
There is no need for the implementation to remember the exact equivalent because as per R5RS it is OK to produce an inexact result given an operation involves an inexact operand. E.g:
Internally, the interpreter can upgrade
2
to afloat
and call the addition operation for floats, there is no need to remember anything:In effect, the above addition in Scheme is treated by the interpreter as: