SPVM::Complex_2f − float Complex Type
use Complex_2f;
my $z : Complex_2f;
# Set
$z−>{re} = 1.5;
$z−>{im} = 2.5;
# Get
my $re = $z−>{re};
my $im = $z−>{im};
"Complex_2f" is a multi−numeric type to represent a float complex number.
See SPVM::Document::Language::Types about multi−numeric types.
has re : float;
A real number.
has im : float;
A imaginary number.
"static method new : Complex_2f ($re : float = 0, $im : float = 0);"
Creates a new Complex_2f multi−numeric value given the real number $re and the imaginary number $im and returns it.
"static method new_array_from_pairs : Complex_2f[] ($pairs : float[]);"
Creates a new Complex_2f 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}]
"static method new_array_from_re_array : Complex_2f[] ($re_array : float[]);"
Creates a new Complex_2f array given real numbers $re_array, and returns the new array.
"static method new_array_from_im_array : Complex_2f[] ($im_array : float[]);"
Creates a new Complex_2f array given imaginary numbers $im_array, and returns the new array.
"static method to_re_array : float[] ($array : Complex_2f[]);"
Converts the Complex_2f array $array to the array of real numbers, and returns it.
"static method to_im_array : float[] ($array : Complex_2f[]);"
Converts the Complex_2f array $array to the array of imaginary numbers, and returns it.
"static method to_pairs : float[] ($array : Complex_2f[]);"
Converts the Complex_2f 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]
"static method to_string : string ($z : Complex_2f);"
Converts the Complex_2f 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";
}
|
• |
Complex_2d |
|||
|
• |
SPVM::Document::Language::Types |
Copyright (c) 2023 Yuki Kimoto
MIT License