Patrick R. Michaud wrote:
On Mon, Aug 31, 2009 at 01:28:08PM -0700, Darren Duncan wrote:
This is a great move; thanks for this change.
So now writing things like 5/43 in code will DWIM and produce a Rat which
maintains the intended value exactly, with no floating-point imprecision;
and so plain 5/43 is now a plain Rat literal, same as 1.23 is.
FWIW, presently the specification somewhat implies that 1.23 is a Num
literal, and doesn't say anything about it producing a Rat.
(Yes, conversations on #perl6 have indicated that it may be otherwise,
but nothing is currently in the spec about it.)
One consequence of all this is that you may no longer write a Num as
C<42.> with just a trailing dot. You must instead say either C<42>
My understanding of Perl 6 to date is that:
Num is effectively a wrapper type that represents a real number some-how and
that internally its representation could either be an Int or a Rat or something
that does IEEE floating-point or something else.
That is, any Int or Rat could be exactly matched by a Num but a Num could also
represent other values that neither an Int nor a Rat can, or that Num can do
approximate (eg, IEEE float) math while Int and Rat would only do exact math
(and so not support certain ops that might result in an irrational).
And so, any context that expects a Num will accept any Int or Rat, but the
reverse may not be true without coersion.
That is, Num will support both exact and inexact numbers, but Int/Rat don't.
Therefore, any literal such as 42.0, because it is exact, should be interpreted
as a plain Rat, same as 42 is interpreted as a plain Int, but they would still
work with any context wanting a Num.
I also don't think this interpretation would harm type-based routine dispatch
since using Rat ops on Rat-compatible inputs would still produce results
suitable for use in Num contexts, I would think.
-- Darren Duncan