See Original text in context
method Int(Num:)
Converts the number to an Int. Fails with X::Numeric::CannotConvert
if the invocant isNaN or Inf
/-Inf
. No rounding is performed.
See Original text in context
method Int(IO::Path: --> Int)
Coerces basename
to Int. fail
with X::Str::Numeric
if base name is not numerical.
See Original text in context
method Int(Rational: --> Int)
Coerces the invocant to Int by truncating non-whole portion of the represented number, if any. If the denominator is zero, will fail with X::Numeric::DivideByZero
.
See Original text in context
multi method Int(::?CLASS:)
Takes a value of an enum and returns it after coercion to Int
:
( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );say cool.Int; # OUTPUT: «42»say almost-pi.Int; # OUTPUT: «3»try say sqrt-n-one.Int;say $!.message if $!; # OUTPUT: «Cannot convert 0+1i to Int: imaginary part not zero»
Note that if the value cannot be coerced to Int
, an exception will be thrown.
See Original text in context
method Int(Match: --> Int)
Tries to convert stringified result of the matched text into Int.
say ('12345' ~~ /234/).Int; # OUTPUT: «234»say ('12345' ~~ /234/).Int.^name; # OUTPUT: «Int»# the next line produces a warning about using Nil (result of a no match) in numeric contextsay ('one-two' ~~ /234/).Int; # OUTPUT: «0» # because Nil.Int returns 0
See Original text in context
method Int
Returns the integer value of the IntStr
.
See Original text in context
multi method Int(StrDistance:)
Returns the distance between the string before and after the transformation.
See Original text in context
multi method Int(Bool --> Int)
Returns the value part of the enum
pair.
say False.Int; # OUTPUT: «0»say True.Int; # OUTPUT: «1»
See Original text in context
method Int(Map: --> Int)
Returns the number of pairs stored in the Map
(same as .elems
).
my = Map.new('a' => 2, 'b' => 17);say .Int; # OUTPUT: «2»
See Original text in context
method Int(Real:)
Calls the Bridge
method on the invocant and then the Int
method on its return value.
See Original text in context
multi method Int()
Coerces the invocant to a Numeric and calls its .Int
method. Fails if the coercion to a Numeric
cannot be done.
say 1+0i.Int; # OUTPUT: «1»say <2e1>.Int; # OUTPUT: «20»say 1.3.Int; # OUTPUT: «1»say (-4/3).Int; # OUTPUT: «-1»say "foo".Int.^name; # OUTPUT: «Failure»
See Original text in context
method Int(Str: --> Int)
Coerces the string to Int, using the same rules as Str.Numeric
.
See Original text in context
method Int(List: --> Int)
Returns the number of elements in the list (same as .elems
).
say (1,2,3,4,5).Int; # OUTPUT: «5»