method Real

Documentation for method Real assembled from the following types:

class Complex

From Complex

(Complex) method Real

Defined as:

multi method Real(Complex:D: --> Num:D)
multi method Real(Complex:U: --> Num:D)

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:D:)

Takes a value of an enum and returns it after coercion to Real:

enum Numbers ( 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.

class ComplexStr

From ComplexStr

(ComplexStr) method Real

Defined as:

multi method Real(ComplexStr:D: --> Num:D)
multi method Real(ComplexStr:U: --> Num:D)

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 IntStr

From IntStr

(IntStr) method Real

Defined as:

multi method Real(IntStr:D: --> Int:D)
multi method Real(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.

role Real

From Real

(Real) method Real

Defined as:

multi method Real(Real:D: --> Real:D)
multi method Real(Real:U: --> Real: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.

class NumStr

From NumStr

(NumStr) method Real

Defined as:

multi method Real(NumStr:D: --> Num:D)
multi method Real(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.

class RatStr

From RatStr

(RatStr) method Real

Defined as:

multi method Real(Real:D: --> Rat:D)
multi method Real(Real: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.