[racket] Question about round
On Sep 30, 2011, at 12:31 PM, Robby Findler wrote:
> Just to clear up one more possible point: the rational? predicate
> actually recognizes inexact numbers, eg:
>
> [robby at penghu] ~/git/plt/collects/drracket/private$ racket
> Welcome to Racket v5.1.3.9.
>> (rational? (sqrt 2))
> #t
Interesting. I hadn't thought of that. Technically, the floating-point approximation to (sqrt 2) is in fact a rational number...
I guess one could say that "rational?" returns false for anything represented in floating point. Which would lead to the odd paradox of some integers not being rational.
The underlying question, it seems to me, is how closely we want to tie the numeric predicates to internal machine representations.
In C/C++/Java, there are two kinds of numbers (ignoring precision): exact ints and inexact floats. The different types in the language correspond exactly to different binary representations.
In Racket, as I understand it, integerhood and exactness are orthogonal: you can have either one with or without the other. I assume that all inexact numbers (integer or not) are represented in floating-point, but don't know how closely exact numbers are tied to a particular binary representation.
Stephen Bloch
sbloch at adelphi.edu