Rat
ErrorsCollection

Rat

Synthesised documentation from type/Num type/RatStr type/Real type/Cool type/Str

From type/Num

See Original text in context

method Rat(Num:D: Real $epsilon = 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.

From type/RatStr

See Original text in context

method Rat

Returns the Rat value of the RatStr.

From type/Real

See Original text in context

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.

From type/Cool

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

From type/Str

See Original text in context

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.