Manpage logo

SPVM::Complex_2d - double Complex Type

Name  Usage  Description  Fields  re  im  Class Methods  new  new_array_from_pairs  new_array_from_re_array  new_array_from_im_array  to_re_array  to_im_array  to_pairs  to_string  See Also  Copyright & License 

Name

SPVM::Complex_2d − double Complex Type

Usage

use Complex_2d;
my $z : Complex_2d;
# Set
$z−>{re} = 1.5;
$z−>{im} = 2.5;
# Get
my $re = $z−>{re};
my $im = $z−>{im};

Description

"Complex_2d" is a multi−numeric type to represent a double complex number.

See SPVM::Document::Language::Types about multi−numeric types.

Fields

re

has re : double;

A real number.

im

has im : double;

A imaginary number.

Class Methods

new

"static method new : Complex_2d ($re : double = 0, $im : double = 0);"

Creates a new Complex_2d multi−numeric value given the real number $re and the imaginary number $im and returns it.

new_array_from_pairs

"static method new_array_from_pairs : Complex_2d[] ($pairs : double[]);"

Creates a new Complex_2d array given the pairs of a real number and an imaginary number $pairs, and returns the new array.

Examples of Input:

# Input Data
[1, 2, 3, 4]
# Data of a new array
[{re => 1, im => 2}, {re => 3, im => 4}]

new_array_from_re_array

"static method new_array_from_re_array : Complex_2d[] ($re_array : double[]);"

Creates a new Complex_2d array given real numbers $re_array, and returns the new array.

new_array_from_im_array

"static method new_array_from_im_array : Complex_2d[] ($im_array : double[]);"

Creates a new Complex_2d array given imaginary numbers $im_array, and returns the new array.

to_re_array

"static method to_re_array : double[] ($array : Complex_2d[]);"

Converts the Complex_2d array $array to the array of real numbers, and returns it.

to_im_array

"static method to_im_array : double[] ($array : Complex_2d[]);"

Converts the Complex_2d array $array to the array of imaginary numbers, and returns it.

to_pairs

"static method to_pairs : double[] ($array : Complex_2d[]);"

Converts the Complex_2d array $array to the pairs of a real number and an imaginary number, and returns it.

Examples of Output:

# Input Data
[{re => 1, im => 2}, {re => 3, im => 4}]
# Output
[1, 2, 3, 4]

to_string

"static method to_string : string ($z : Complex_2d);"

Converts the Complex_2d multi−numeric value to a string, such as "1+2i".

Implementation:

my $string = (string)undef;
if ($z−>{im} < 0) {
$string = "$z−>{re}$z−>{im}i";
}
else {
$string = "$z−>{re}+$z−>{im}i";
}

See Also

Complex_2f

SPVM::Document::Language::Types

Copyright & License

Copyright (c) 2023 Yuki Kimoto

MIT License


Updated 2026-06-01 - jenkler.se | uex.se