[racket] Question about round
On 09/29/2011 03:11 PM, Mark Engelberg wrote:
> I'm a bit baffled by this behavior:
>
> > (exact? (round (sin 30)))
> #f
> > (integer? (round (sin 30)))
> #t
> >
>
> How is it possible to have an inexact integer?
> (inexact? 1.0)
#t
The interpretation of "inexact" is subtle and contentious. But to a
first approximation, "inexact" just means "floating-point".
To a second approximation, I interpret
(integer? 1.0) = #t
(inexact? 1.0) = #t
as "the representation is definitely an integer, but it may not exactly
represent the quantity you really wanted to talk about". But I haven't
studied this carefully, and it is possible that my interpretation is
horribly wrong according to someone.
The pragmatic answer is you generally have to write
(inexact->exact (round x))
which is annoying, but no one has yet bothered to add a standard library
function for this, as far as I know.
Note also that round does not necessarily return an integer:
> (round +inf.0)
+inf.0
Ryan