classNumStris Allomorph isNum { }
NumStr
is a dual value type, a subclass of both Allomorph
, hence Str
, and Num
.
See Allomorph
for further details.
my$num-str=<42.1e0>; say$num-str.^name; # OUTPUT: «NumStr» myNum$num=$num-str; # OK! myStr$str=$num-str; # OK! # ∈ operator cares about object identity say 42e10 ∈ <42e10 55 1>; # OUTPUT: «False»
Methods§
method new§
methodnew(Num$i,Str$s)
The constructor requires both the Num
and the Str
value, when constructing one directly the values can be whatever is required:
my$f=NumStr.new(42.1e0,"forty two and a bit"); say+$f; # OUTPUT: «42.1» say~$f; # OUTPUT: «"forty two and a bit"»
method Num§
methodNum
Returns the Num
value of the NumStr
.
method Numeric§
multimethodNumeric(NumStr:D: --> Num:D) multimethodNumeric(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
.
method Real§
multimethodReal(NumStr:D: --> Num:D) multimethodReal(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
.
Operators§
infix ===
§
multi infix:<===>(NumStr:D $a, NumStr:D $b)
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.
Typegraph§
NumStr