Documentation for method Real
assembled from the following pages:
Class: IntStr §
From IntStr
(IntStr) method Real §
Defined as:
multi method Real(IntStr: --> Int)multi method Real(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: RatStr §
From RatStr
(RatStr) method Real §
Defined as:
multi method Real(Real: --> Rat)multi method Real(Real: --> 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: NumStr §
From NumStr
(NumStr) method Real §
Defined as:
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
.
Class: ComplexStr §
From ComplexStr
(ComplexStr) method Real §
Defined as:
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
.
Class: Complex §
From Complex
(Complex) method Real §
Defined as:
multi method Real(Complex: --> Num)multi method Real(Complex: --> Num)
Coerces 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
.
Role: Enumeration §
From Enumeration
(Enumeration) method Real §
Defined as:
multi method Real(::?CLASS:)
Takes a value of an enum and returns it after coercion to Real
:
( cool => '42', almost-pi => '3.14', sqrt-n-one => 'i' );say cool.Real; # OUTPUT: «42» say almost-pi.Real; # OUTPUT: «3.14» try say sqrt-n-one.Real;say $!.message if $!; # OUTPUT: «Cannot convert 0+1i to Real: imaginary part not zero»
Note that if the value cannot be coerced to Real
, an exception will be thrown.
Role: Real §
From Real
(Real) method Real §
Defined as:
multi method Real(Real: --> Real)multi method Real(Real: --> Real)
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: Cool §
From Cool
(Cool) method Real §
Defined as:
multi method Real()
Coerces the invocant to a Numeric
and calls its .Real
method. Fails if the coercion to a Numeric
cannot be done.
say 1+0i.Real; # OUTPUT: «1» say 2e1.Real; # OUTPUT: «20» say 1.3.Real; # OUTPUT: «1.3» say (-4/3).Real; # OUTPUT: «-1.333333» say "foo".Real.^name; # OUTPUT: «Failure»