On 09/23/2012 05:40 PM, John Clements wrote:
I'm trying to convert a list of Reals into a list of Floats, and the natural choice is
(map exact->inexact l). Unfortunately, it appears that exact->inexact produces
Inexact-Reals, not flonums. Taking a look at the type expansions, I see that the
difference is that Inexact-Real includes *single-*flonums. I'm guessing--and this is
just a guess--that the only situation where exact->inexact will produce
single-flonums is when it's *given* a single-flonum.
If I'm right, then it's safe for me to stick in a predicate that detects and fails
on results that aren't flonums. If I'm wrong, then exact->inexact might spit
out a single-flonum when given, say, 19. That would be a problem. Is my conjecture
correct?
I would suggest some kind of change to TR here, but honestly I can see that
fixing this would probably be a big pain.
You're right that `exact->inexact' only returns a single flonum when
given one. Use `real->double-flonum' instead.
(Yes, its verbosity is ridiculous. I got tired of it and reexported it
as `fl' from `math/flonum'. I can write (flsqrt (+ (fl a) (fl b))), for
example. It's nice.)
If there's a user-interface problem here, it's that Racket has two kinds
of inexact numbers. TR is just forcing you to deal with that reality so
it can guarantee your program won't crash.
Neil ⊥
____________________
Racket Users list:
http://lists.racket-lang.org/users