In RatStr§

See primary documentation in context for method Rat

method Rat

Returns the Rat value of the RatStr.

In role Real§

See primary documentation in context for method Rat

method Rat(Real:D: Real $epsilon = 1e-6)

Calls the Bridge method on the invocant and then the Rat method on its return value with the $epsilon argument.

In Cool§

See primary documentation in context for method Rat

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.denominatorfor π.Rat# OUTPUT: «(355 113)␤»

In Str§

See primary documentation in context for method Rat

method Rat(Str:D: --> Rational:D)

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.

In Num§

See primary documentation in context for method Rat

method Rat(Num:D: Real $epsilon = 1e-6)

Converts the number to a Rat with $epsilon precision. If the invocant is an Inf, -Inf, or NaN, converts them to a Rat with 0 denominator and 1, -1, or 0 numerator, respectively.