Documentation for routine Numeric
assembled from the following pages:
Class: IntStr §
From IntStr
(IntStr) method Numeric §
Defined as:
multi method Numeric(IntStr: --> Int)multi method Numeric(IntStr: --> Int)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns value 0
.
Class: Thread §
From Thread
(Thread) method Numeric §
method Numeric(Thread: --> Int)
Returns a numeric, unique thread identifier, i.e. the same as id.
Class: RatStr §
From RatStr
(RatStr) method Numeric §
Defined as:
multi method Numeric(RatStr: --> Rat)multi method Numeric(RatStr: --> Rat)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns value 0.0
.
Class: X::AdHoc §
From X::AdHoc
(X::AdHoc) method Numeric §
Defined as
method Numeric()
Converts the payload to Numeric
and returns it
Role: Sequence §
From Sequence
(Sequence) method Numeric §
method Numeric(::?CLASS:)
Returns the number of elements in the cached sequence.
Class: List §
From List
(List) method Numeric §
Defined as:
method Numeric(List: --> Int)
Returns the number of elements in the list (same as .elems
).
say (1,2,3,4,5).Numeric; # OUTPUT: «5»
Class: Nil §
From Nil
(Nil) method Numeric §
method Numeric()
Warns the user that they tried to numify a Nil
.
Class: NumStr §
From NumStr
(NumStr) method Numeric §
Defined as:
multi method Numeric(NumStr: --> Num)multi method Numeric(NumStr: --> Num)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns value 0e0
.
Class: Numeric §
From Numeric
(Numeric) method Numeric §
Defined as:
multi method Numeric(Numeric: --> Numeric)multi method Numeric(Numeric: --> Numeric)
The :D
variant simply returns the invocant. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns self.new
.
Class: Map §
From Map
(Map) method Numeric §
Defined as:
method Numeric(Map: --> Int)
Returns the number of pairs stored in the Map
(same as .elems
).
my = Map.new('a' => 2, 'b' => 17);say .Numeric; # OUTPUT: «2»
Class: ComplexStr §
From ComplexStr
(ComplexStr) method Numeric §
Defined as:
multi method Numeric(ComplexStr: --> Complex)multi method Numeric(ComplexStr: --> Complex)
The :D
variant returns the numeric portion of the invocant. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns value <0+0i>
.
Enum: Bool §
From Bool
(Bool) routine Numeric §
multi method Numeric(Bool --> Int)
Returns the value part of the enum
pair.
say False.Numeric; # OUTPUT: «0» say True.Numeric; # OUTPUT: «1»
Class: IO::Path §
From IO::Path
(IO::Path) method Numeric §
Defined as:
method Numeric(IO::Path: --> Numeric)
Coerces .basename
to Numeric. Fails with X::Str::Numeric
if base name is not numerical.
Class: Str §
From Str
(Str) method Numeric §
Defined as:
method Numeric(Str: --> Numeric)
Coerces the string to Numeric using semantics equivalent to val routine. Fails with X::Str::Numeric
if the coercion to a number cannot be done.
Only Unicode characters with property Nd
, as well as leading and trailing whitespace are allowed, with the special case of the empty string being coerced to 0
. Synthetic codepoints (e.g. "7\x[308]"
) are forbidden.
While Nl
and No
characters can be used as numeric literals in the language, their conversion via Str.Numeric
will fail, by design; the same will happen with synthetic numerics (composed of numbers and diacritic marks). See unival if you need to coerce such characters to Numeric
. +, - and the Unicode MINUS SIGN − are all allowed.
" −33".Numeric; # OUTPUT: «-33»
Enum: Endian §
From Endian
(Endian) routine Numeric §
multi method Numeric(Endian --> Int)
Returns the value part of the enum
pair.
say NativeEndian.Numeric; # OUTPUT: «0» say LittleEndian.Numeric; # OUTPUT: «1» say BigEndian.Numeric; # OUTPUT: «2»
Note that the actual numeric values are subject to change. So please use the named values instead.
Class: Capture §
From Capture
(Capture) method Numeric §
Defined as:
method Numeric(Capture: --> Int)
Returns the number of positional elements in the Capture
.
say \(1,2,3, apples => 2).Numeric; # OUTPUT: «3»
Role: Enumeration §
From Enumeration
(Enumeration) method Numeric §
Defined as:
multi method Numeric(::?CLASS:)
Takes a value of an enum and returns it after coercion to Numeric
:
( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );say cool.Numeric; # OUTPUT: «42» say almost-pi.Numeric; # OUTPUT: «3.14» say sqrt-n-one.Numeric; # OUTPUT: «0+1i»
Note that if the value cannot be coerced to Numeric
, an exception will be thrown.
Class: StrDistance §
From StrDistance
(StrDistance) method Numeric §
Returns the distance as a number.