is Allomorph is Num
NumStr
is a dual value type, a subclass of both Allomorph
, hence Str
, and Num
.
See Allomorph
for further details.
my = <42.1e0>;say .^name; # OUTPUT: «NumStr»my Num = ; # OK!my Str = ; # OK!# ∈ operator cares about object identitysay 42e10 ∈ <42e10 55 1>; # OUTPUT: «False»
Methods§
method new§
method new(Num , Str )
The constructor requires both the Num
and the Str
value, when constructing one directly the values can be whatever is required:
my = NumStr.new(42.1e0, "forty two and a bit");say +; # OUTPUT: «42.1»say ~; # OUTPUT: «"forty two and a bit"»
method Num§
method Num
Returns the Num
value of the NumStr
.
method Numeric§
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
.
method Real§
multi method Real(NumStr: --> Num)multi method Real(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
.
Operators§
infix ===
§
multi infix:<===>(NumStr , NumStr )
NumStr
Value identity operator. Returns True
if the Num
values of $a
and $b
are identical and their Str
values are also identical. Returns False
otherwise.