See Original text in context
method Rat(Num: Real = 1e-6)
Converts the number to a Rat with $epsilon
precision. If the invocant is a Inf
, -Inf
, or a NaN
, converts them to a Rat with 0
denominator and 1
, -1
, or 0
numerator, respectively.
See Original text in context
method Rat
Returns the Rat
value of the RatStr
.
See Original text in context
method Rat(Real: Real = 1e-6)
Calls the Bridge
method on the invocant and then the Rat
method on its return value with the $epsilon
argument.
See Original text in context
multi method Rat()
Coerces the invocant to a Numeric and calls its .Rat
method. Fails if the coercion to a Numeric
cannot be done.
say 1+0i.Rat; # OUTPUT: «1»say 2e1.Rat; # OUTPUT: «20»say (-4/3).Rat; # OUTPUT: «-1.333333»say "foo".Rat.^name; # OUTPUT: «Failure»say (.numerator, .denominator) for π.Rat; # OUTPUT: «(355 113)»
See Original text in context
method Rat(Str: --> Rational)
Coerces the string to a Rat object, using the same rules as Str.Numeric
. If the denominator is larger than 64-bits is it still kept and no degradation to Num
occurs.