develooper Front page | perl.perl6.users | Postings from September 2018

Re: Rat

Thread Previous | Thread Next
September 17, 2018 05:54
Re: Rat
Message ID:
On 9/16/18 7:37 PM, Curt Tilmes wrote:
> Rat is a type (a 'class').
> It is also a method on class Numeric.  You can take anything Numeric, 
> and call .Rat() on it to get an equivalent Rat (well, within $epsilon)
> You can't, for example, say
> my Rat $x = pi;
> Since pi is not rational -- it won't fit in that box.
> You can, however, ask pi to turn itself into a Rat (or something pretty 
> close), then it will fit.
> my Rat $x = pi.Rat;

Hi Curt,

I just wrapped my brain around "Role" (Real) being
a superset of "Class" (Rat).  When you tell somethig
it isa Rol, it can take on any of the clasees in its subset.
If yo want somethinbg specific, use a class.

And now I understand.

Thank you,

Just out of curiosity, how does Perl handle an
irrational number, like pi or the square root of two?
A number that keeps going on and on and on ...

As an engineer, it is all about significance.  1.0
is not the same as 1.00 to an engineer.  So
we don't care about run on numbers.  We just
use the significant part.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About