r5rs requires that integer? return #t when (= x (round x))
r5rs requires round to preserve exactness
Now, round is an optional function (USE_MATH). I suggest that it should not be optional, rather that there be versions for USE_MATH and !USE_MATH; the !USE_MATH version could simply do
s_return(sc, ivalue(x)); /* truncate is not round, but is close enough for integer? to work */
In any case, once we have round, init.scm can contain:
; Utilities for math. Notice that inexact->exact is primitive,
; but exact->inexact is not.
(define exact? integer?)
;(define (inexact? x) (and (real? x) (not (integer? x))))
(define (inexact? x) (not (exact? x)))
; If x is an inexact real number, then (integer? x) is true if and only if (= x (round x))
(define round_ round)
(define (integer? x) (or (exact? x) (= x (round_ x))))
; round shoud return an exact if given an exact
(define (round x) (if (exact? x) x (round_ x)))
Log in to post a comment.