In Num§
See primary documentation in context for method Int.
methodInt(Num:D:)
Converts the number to an Int
. Fails with X::Numeric::CannotConvert
if the invocant is a NaN
or Inf
/-Inf
. No rounding is performed.
In Cool§
See primary documentation in context for method Int.
multimethodInt()
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»
In Date§
See primary documentation in context for method Int.
multimethodInt(Date:D: --> Int:D)
Converts the invocant to Int
. The same value can be obtained with the daycount
method.
Available as of release 2023.02 of the Rakudo compiler.
In Map§
See primary documentation in context for method Int.
methodInt(Map:D: --> Int:D)
Returns the number of pairs stored in the Map
(same as .elems
).
my$m=Map.new('a'=> 2,'b'=> 17); say$m.Int; # OUTPUT: «2»
In List§
See primary documentation in context for method Int.
methodInt(List:D: --> Int:D)
Returns the number of elements in the list (same as .elems
).
say (1,2,3,4,5).Int; # OUTPUT: «5»
In role Real§
See primary documentation in context for method Int.
methodInt(Real:D:)
Calls the Bridge
method on the invocant and then the Int
method on its return value.
In Match§
See primary documentation in context for method Int.
methodInt(Match:D: --> Int:D)
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 context say ('one-two'~~ /234/).Int; # OUTPUT: «0» # because Nil.Int returns 0
In enum Bool§
See primary documentation in context for routine Int.
multimethodInt(Bool:D --> Int:D)
Returns the value part of the enum
pair.
sayFalse.Int; # OUTPUT: «0» sayTrue.Int; # OUTPUT: «1»
In IntStr§
See primary documentation in context for method Int.
methodInt
Returns the integer value of the IntStr
.
In role Enumeration§
See primary documentation in context for method Int.
multimethodInt(::?CLASS:D:)
Takes a value of an enum and returns it after coercion to Int
:
enum Numbers ( cool =>'42', almost-pi =>'3.14', sqrt-n-one =>'i' ); say cool.Int; # OUTPUT: «42» say almost-pi.Int; # OUTPUT: «3» trysay sqrt-n-one.Int; say $!.messageif $!; # 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.
In IO::Path§
See primary documentation in context for method Int.
methodInt(IO::Path:D: --> Int:D)
Coerces .basename
to Int
. Fails with X::Str::Numeric
if base name is not numerical.
In StrDistance§
See primary documentation in context for method Int.
multimethodInt(StrDistance:D:)
Returns the distance between the string before and after the transformation.
In role Rational§
See primary documentation in context for method Int.
methodInt(Rational:D: --> Int:D)
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
.
In Str§
See primary documentation in context for method Int.
methodInt(Str:D: --> Int:D)
Coerces the string to Int
, using the same rules as Str.Numeric
.