blib/lib/SPVM/Complex_2d.pm untested

filter: Statementstmt n/a Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a SCAR -
1 =head1 Name
2  
3 SPVM::Complex_2d - double Complex Type
4  
5 =head1 Usage
6
7 use Complex_2d;
8
9 my $z : Complex_2d;
10
11 # Set
12 $z->{re} = 1.5;
13 $z->{im} = 2.5;
14
15 # Get
16 my $re = $z->{re};
17 my $im = $z->{im};
18  
19 =head1 Description
20  
21 C<Complex_2d> is a multi-numeric type to represent a double complex number.
22  
23 See L<SPVM::Document::Language::Types> about multi-numeric types.
24  
25 =head1 Fields
26  
27 =head2 re
28  
29 has re : double;
30  
31 A real number.
32  
33 =head2 im
34  
35 has im : double;
36  
37 A imaginary number.
38  
39 =head2 Class Methods
40  
41 =head2 new
42  
43 C<static method new : L<Complex_2d|SPVM::Complex_2d> ($re : double = 0, $im : double = 0);>
44  
45 Creates a new L<Complex_2d|SPVM::Complex_2d> multi-numeric value given the real number $re and the imaginary number $im and returns it.
46  
47 =head2 new_array_from_pairs
48  
49 C<static method new_array_from_pairs : L<Complex_2d|SPVM::Complex_2d>[] ($pairs : double[]);>
50  
51 Creates a new L<Complex_2d|SPVM::Complex_2d> array given the pairs of a real number and an imaginary number $pairs, and returns the new array.
52  
53 Examples of Input:
54
55 # Input Data
56 [1, 2, 3, 4]
57
58 # Data of a new array
59 [{re => 1, im => 2}, {re => 3, im => 4}]
60  
61 =head2 new_array_from_re_array
62  
63 C<static method new_array_from_re_array : L<Complex_2d|SPVM::Complex_2d>[] ($re_array : double[]);>
64  
65 Creates a new L<Complex_2d|SPVM::Complex_2d> array given real numbers $re_array, and returns the new array.
66  
67 =head2 new_array_from_im_array
68  
69 C<static method new_array_from_im_array : L<Complex_2d|SPVM::Complex_2d>[] ($im_array : double[]);>
70  
71 Creates a new L<Complex_2d|SPVM::Complex_2d> array given imaginary numbers $im_array, and returns the new array.
72  
73 =head2 to_re_array
74  
75 C<static method to_re_array : double[] ($array : L<Complex_2d|SPVM::Complex_2d>[]);>
76  
77 Converts the L<Complex_2d|SPVM::Complex_2d> array $array to the array of real numbers, and returns it.
78  
79 =head2 to_im_array
80  
81 C<static method to_im_array : double[] ($array : L<Complex_2d|SPVM::Complex_2d>[]);>
82  
83 Converts the L<Complex_2d|SPVM::Complex_2d> array $array to the array of imaginary numbers, and returns it.
84  
85 =head2 to_pairs
86  
87 C<static method to_pairs : double[] ($array : L<Complex_2d|SPVM::Complex_2d>[]);>
88  
89 Converts the L<Complex_2d|SPVM::Complex_2d> array $array to the pairs of a real number and an imaginary number, and returns it.
90  
91 Examples of Output:
92
93 # Input Data
94 [{re => 1, im => 2}, {re => 3, im => 4}]
95
96 # Output
97 [1, 2, 3, 4]
98  
99 =head2 to_string
100  
101 C<static method to_string : string ($z : L<Complex_2d|SPVM::Complex_2d>);>
102  
103 Converts the L<Complex_2d|SPVM::Complex_2d> multi-numeric value to a string, such as C<1+2i>.
104  
105 Implementation:
106  
107 my $string = (string)undef;
108 if ($z->{im} < 0) {
109 $string = "$z->{re}$z->{im}i";
110 }
111 else {
112 $string = "$z->{re}+$z->{im}i";
113 }
114  
115 =head1 See Also
116  
117 =over 2
118  
119 =item * L<Complex_2f|SPVM::Complex_2f>
120  
121 =item * L<SPVM::Document::Language::Types>
122  
123 =back
124  
125 =head1 Copyright & License
126  
127 Copyright (c) 2023 Yuki Kimoto
128  
129 MIT License