The Rat routine

Combined from primary sources listed below.

In class Num ( Type/Num )§

See primary docmentation in context for method Rat.

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.

In class Cool ( Type/Cool )§

See primary docmentation in context for method Rat.

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 class RatStr ( Type/RatStr )§

See primary docmentation in context for method Rat.

method Rat§

method Rat

Returns the Rat value of the RatStr.

In class Str ( Type/Str )§

See primary docmentation in context for method Rat.

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 role Real ( Type/Real )§

See primary docmentation in context for method Rat.

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.