txt: ## numeric.md
  Numeric
  
  Combined from primary sources listed below.
  
  # [In List](#___top "go to top of document")[§](#(List)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/List#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(List:D: --> Int:D)
  ```
  
  Returns the number of elements in the list (same as `.elems`).
  
  ```raku
  say (1,2,3,4,5).Numeric; # OUTPUT: «5␤»
  ```
  
  # [In role Sequence](#___top "go to top of document")[§](#(role_Sequence)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Sequence#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(::?CLASS:D:)
  ```
  
  Returns the number of elements in the [cached](/type/PositionalBindFailover#method_cache) sequence.
  
  # [In Capture](#___top "go to top of document")[§](#(Capture)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Capture#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(Capture:D: --> Int:D)
  ```
  
  Returns the number of positional elements in the `Capture`.
  
  ```raku
  say \(1,2,3, apples => 2).Numeric; # OUTPUT: «3␤»
  ```
  
  # [In enum Bool](#___top "go to top of document")[§](#(enum_Bool)_routine_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Bool#routine_Numeric)
  for **routine Numeric**.
  
  ```raku
  multi method Numeric(Bool:D --> Int:D)
  ```
  
  Returns the value part of the `enum` pair.
  
  ```raku
  say False.Numeric;                                # OUTPUT: «0␤»
  say True.Numeric;                                 # OUTPUT: «1␤»
  ```
  
  # [In X::AdHoc](#___top "go to top of document")[§](#(X::AdHoc)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/X/AdHoc#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric()
  ```
  
  Converts the payload to [`Numeric`](/type/Numeric) and returns it
  
  # [In IntStr](#___top "go to top of document")[§](#(IntStr)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/IntStr#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(IntStr:D: --> Int:D)
  multi method Numeric(IntStr:U: --> Int:D)
  ```
  
  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`.
  
  # [In Str](#___top "go to top of document")[§](#(Str)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Str#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(Str:D: --> Numeric:D)
  ```
  
  Coerces the string to [`Numeric`](/type/Numeric) using semantics equivalent to [val](/routine/val) routine. [Fails](/routine/fail) with [`X::Str::Numeric`](/type/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](/routine/unival) if you need to coerce such characters to [`Numeric`](/type/Numeric). +, - and the Unicode MINUS SIGN − are all allowed.
  
  ```raku
  " −33".Numeric;       # OUTPUT: «-33␤»
  
  ```
  
  # [In role Enumeration](#___top "go to top of document")[§](#(role_Enumeration)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Enumeration#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(::?CLASS:D:)
  ```
  
  Takes a value of an enum and returns it after coercion to [`Numeric`](/type/Numeric):
  
  ```raku
  enum Numbers ( 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`](/type/Numeric), an exception will be thrown.
  
  # [In NumStr](#___top "go to top of document")[§](#(NumStr)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/NumStr#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(NumStr:D: --> Num:D)
  multi method Numeric(NumStr:U: --> Num:D)
  ```
  
  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`.
  
  # [In StrDistance](#___top "go to top of document")[§](#(StrDistance)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/StrDistance#method_Numeric)
  for **method Numeric**.
  
  Returns the distance as a number.
  
  # [In Map](#___top "go to top of document")[§](#(Map)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Map#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(Map:D: --> Int:D)
  ```
  
  Returns the number of pairs stored in the `Map` (same as `.elems`).
  
  ```raku
  my $m = Map.new('a' => 2, 'b' => 17);
  say $m.Numeric;                                   # OUTPUT: «2␤»
  ```
  
  # [In Nil](#___top "go to top of document")[§](#(Nil)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Nil#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric()
  ```
  
  Warns the user that they tried to numify a `Nil`.
  
  # [In enum Endian](#___top "go to top of document")[§](#(enum_Endian)_routine_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Endian#routine_Numeric)
  for **routine Numeric**.
  
  ```raku
  multi method Numeric(Endian:D --> Int:D)
  ```
  
  Returns the value part of the `enum` pair.
  
  ```raku
  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.
  
  # [In IO::Path](#___top "go to top of document")[§](#(IO::Path)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/IO/Path#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(IO::Path:D: --> Numeric:D)
  ```
  
  Coerces [`.basename`](/routine/basename) to [`Numeric`](/type/Numeric). [Fails](/routine/fail) with [`X::Str::Numeric`](/type/X/Str/Numeric) if base name is not numerical.
  
  # [In Thread](#___top "go to top of document")[§](#(Thread)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Thread#method_Numeric)
  for **method Numeric**.
  
  ```raku
  method Numeric(Thread:D: --> Int:D)
  ```
  
  Returns a numeric, unique thread identifier, i.e. the same as [id](#method_id).
  
  # [In role Numeric](#___top "go to top of document")[§](#(role_Numeric)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Numeric#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(Numeric:D: --> Numeric:D)
  multi method Numeric(Numeric:U: --> Numeric:D)
  ```
  
  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`.
  
  # [In DateTime](#___top "go to top of document")[§](#(DateTime)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/DateTime#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(DateTime:D: --> Instant:D)
  ```
  
  Available as of the 2021.09 release of the Rakudo compiler.
  
  Converts the invocant to [`Instant`](/type/Instant). The same value can be obtained with the [`Instant`](/type/Instant) method. This allows `DateTime` objects to be used directly in arithmetic operations.
  
  # [In ComplexStr](#___top "go to top of document")[§](#(ComplexStr)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/ComplexStr#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(ComplexStr:D: --> Complex:D)
  multi method Numeric(ComplexStr:U: --> Complex:D)
  ```
  
  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>`.
  
  # [In RatStr](#___top "go to top of document")[§](#(RatStr)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/RatStr#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(RatStr:D: --> Rat:D)
  multi method Numeric(RatStr:U: --> Rat:D)
  ```
  
  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`.
  
  # [In Date](#___top "go to top of document")[§](#(Date)_method_Numeric "direct link")
  
  See primary documentation
  [in context](/type/Date#method_Numeric)
  for **method Numeric**.
  
  ```raku
  multi method Numeric(Date:D: --> Int:D)
  ```
  
  Converts the invocant to [`Int`](/type/Int). The same value can be obtained with the `daycount` method. This allows `Date` objects to be used directly in arithmetic operations.
  
  Available as of release 2023.02 of the Rakudo compiler.
  