The Num routine

Combined from primary sources listed below.

In class NumStr ( Type/NumStr )§

See primary docmentation in context for method Num.

method Num§

method Num

Returns the Num value of the NumStr.

In class Num ( Type/Num )§

See primary docmentation in context for method Num.

method Num§

method Num()

Returns the invocant.

In class Cool ( Type/Cool )§

See primary docmentation in context for method Num.

method Num§

multi method Num()

Coerces the invocant to a Numeric and calls its .Num method. Fails if the coercion to a Numeric cannot be done.

say 1+0i.Num;             # OUTPUT: «1␤»
say 2e1.Num;              # OUTPUT: «20␤»
say (16/9)².Num;          # OUTPUT: «3.1604938271604937␤»
say (-4/3).Num;           # OUTPUT: «-1.3333333333333333␤»
say "foo".Num.^name;      # OUTPUT: «Failure␤»

In role Rational ( Type/Rational )§

See primary docmentation in context for method Num.

method Num§

method Num(Rational:D: --> Num:D)

Coerces the invocant to Num by dividing numerator by denominator. If denominator is 0, returns Inf, -Inf, or NaN, based on whether numerator is a positive number, negative number, or 0, respectively.

In class Str ( Type/Str )§

See primary docmentation in context for method Num.

method Num§

method Num(Str:D: --> Num:D)

Coerces the string to Num, using the same rules as Str.Numeric and handling negative zero, -0e0, and positive zero, 0e0.

my Str $s = "-0/5";
say (.self, .^namegiven $s.Numeric;  # OUTPUT: «(0 Rat)␤»
say (.self, .^namegiven $s.Num;      # OUTPUT: «(-0 Num)␤»

In role Real ( Type/Real )§

See primary docmentation in context for method Num.

method Num§

method Num(Real:D:)

Calls the Bridge method on the invocant and then the Num method on its return value.