Dual value complex number and string
is Allomorph is Complex
ComplexStr
is a dual value type, a subclass of both Allomorph
, hence Str
, and Complex
.
See Allomorph
for further details.
my = <42+0i>;say .^name; # OUTPUT: «ComplexStr»my Complex = ; # OK!my Str = ; # OK!# ∈ operator cares about object identitysay 42+0i ∈ <42+0i 55 1>; # OUTPUT: «False»
method new(Complex , Str )
The constructor requires both the Complex
and the Str
value, when constructing one directly the values can be whatever is required:
my = ComplexStr.new(42+0i, "forty two (but complicated)");say +; # OUTPUT: «42+0i»say ~; # OUTPUT: «"forty two (but complicated)"»
method Capture(ComplexStr: --> Capture)
Equivalent to Mu.Capture
.
method Complex
Returns the Complex
value of the ComplexStr
.
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>
.
multi method Real(ComplexStr: --> Num)multi method Real(ComplexStr: --> Num)
Coerces the numeric portion of the invocant to Num. If the imaginary part isn't approximately zero, coercion fails with X::Numeric::Real
.
The :D
variant returns the result of that coercion. The :U
variant issues a warning about using an uninitialized value in numeric context and then returns value 0e0
.
===
multi sub infix:<===>(ComplexStr , ComplexStr )
ComplexStr
Value identity operator. Returns True
if the Complex
values of $a
and $b
are identical and their Str
values are also identical. Returns False
otherwise.