| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# |
|
2
|
|
|
|
|
|
|
# This file is part of Language::Befunge. |
|
3
|
|
|
|
|
|
|
# Copyright (c) 2001-2009 Jerome Quelin, all rights reserved. |
|
4
|
|
|
|
|
|
|
# |
|
5
|
|
|
|
|
|
|
# This program is free software; you can redistribute it and/or modify |
|
6
|
|
|
|
|
|
|
# it under the same terms as Perl itself. |
|
7
|
|
|
|
|
|
|
# |
|
8
|
|
|
|
|
|
|
# |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
package Language::Befunge::lib::CPLI; |
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
3811
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
28
|
|
|
13
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
22
|
|
|
14
|
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
7
|
use Math::Complex; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
827
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
0
|
|
|
0
|
1
|
|
sub new { return bless {}, shift; } |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# -- operations |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# |
|
23
|
|
|
|
|
|
|
# ($r, $i) = A( $ar, $ai, $br, $bi ) |
|
24
|
|
|
|
|
|
|
# |
|
25
|
|
|
|
|
|
|
# push ($ar+i*$ai) + ($br+i*$bi) back onto the stack (complex addition) |
|
26
|
|
|
|
|
|
|
# |
|
27
|
|
|
|
|
|
|
sub A { |
|
28
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
29
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# pop the values |
|
32
|
0
|
|
|
|
|
|
my $bi = $ip->spop; |
|
33
|
0
|
|
|
|
|
|
my $br = $ip->spop; |
|
34
|
0
|
|
|
|
|
|
my $ai = $ip->spop; |
|
35
|
0
|
|
|
|
|
|
my $ar = $ip->spop; |
|
36
|
0
|
|
|
|
|
|
my $a = cplx($ar, $ai); |
|
37
|
0
|
|
|
|
|
|
my $b = cplx($br, $bi); |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# push the result |
|
40
|
0
|
|
|
|
|
|
my $c = $a + $b; |
|
41
|
0
|
|
|
|
|
|
$ip->spush( $c->Re, $c->Im ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# |
|
46
|
|
|
|
|
|
|
# ($r, $i) = D( $ar, $ai, $br, $bi ) |
|
47
|
|
|
|
|
|
|
# |
|
48
|
|
|
|
|
|
|
# push ($ar+i*$ai) / ($br+i*$bi) back onto the stack (complex division) |
|
49
|
|
|
|
|
|
|
# |
|
50
|
|
|
|
|
|
|
sub D { |
|
51
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
52
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# pop the values |
|
55
|
0
|
|
|
|
|
|
my $bi = $ip->spop; |
|
56
|
0
|
|
|
|
|
|
my $br = $ip->spop; |
|
57
|
0
|
|
|
|
|
|
my $ai = $ip->spop; |
|
58
|
0
|
|
|
|
|
|
my $ar = $ip->spop; |
|
59
|
0
|
|
|
|
|
|
my $a = cplx($ar, $ai); |
|
60
|
0
|
|
|
|
|
|
my $b = cplx($br, $bi); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# push the result |
|
63
|
0
|
|
|
|
|
|
my $c = $a / $b; |
|
64
|
0
|
|
|
|
|
|
$ip->spush( $c->Re, $c->Im ); |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# |
|
69
|
|
|
|
|
|
|
# ($r, $i) = M( $ar, $ai, $br, $bi ) |
|
70
|
|
|
|
|
|
|
# |
|
71
|
|
|
|
|
|
|
# push ($ar+i*$ai) * ($br+i*$bi) back onto the stack (complex multiplication) |
|
72
|
|
|
|
|
|
|
# |
|
73
|
|
|
|
|
|
|
sub M { |
|
74
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
75
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
# pop the values |
|
78
|
0
|
|
|
|
|
|
my $bi = $ip->spop; |
|
79
|
0
|
|
|
|
|
|
my $br = $ip->spop; |
|
80
|
0
|
|
|
|
|
|
my $ai = $ip->spop; |
|
81
|
0
|
|
|
|
|
|
my $ar = $ip->spop; |
|
82
|
0
|
|
|
|
|
|
my $a = cplx($ar, $ai); |
|
83
|
0
|
|
|
|
|
|
my $b = cplx($br, $bi); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
# push the result |
|
86
|
0
|
|
|
|
|
|
my $c = $a * $b; |
|
87
|
0
|
|
|
|
|
|
$ip->spush( $c->Re, $c->Im ); |
|
88
|
|
|
|
|
|
|
} |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
# |
|
92
|
|
|
|
|
|
|
# ($r, $i) = S( $ar, $ai, $br, $bi ) |
|
93
|
|
|
|
|
|
|
# |
|
94
|
|
|
|
|
|
|
# push ($ar+i*$ai) - ($br+i*$bi) back onto the stack (complex subtraction) |
|
95
|
|
|
|
|
|
|
# |
|
96
|
|
|
|
|
|
|
sub S { |
|
97
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
98
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
# pop the values |
|
101
|
0
|
|
|
|
|
|
my $bi = $ip->spop; |
|
102
|
0
|
|
|
|
|
|
my $br = $ip->spop; |
|
103
|
0
|
|
|
|
|
|
my $ai = $ip->spop; |
|
104
|
0
|
|
|
|
|
|
my $ar = $ip->spop; |
|
105
|
0
|
|
|
|
|
|
my $a = cplx($ar, $ai); |
|
106
|
0
|
|
|
|
|
|
my $b = cplx($br, $bi); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# push the result |
|
109
|
0
|
|
|
|
|
|
my $c = $a - $b; |
|
110
|
0
|
|
|
|
|
|
$ip->spush( $c->Re, $c->Im ); |
|
111
|
|
|
|
|
|
|
} |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
# |
|
115
|
|
|
|
|
|
|
# $n = V( $r, $i ) |
|
116
|
|
|
|
|
|
|
# |
|
117
|
|
|
|
|
|
|
# push absolute value of complex $r+i*$i |
|
118
|
|
|
|
|
|
|
# |
|
119
|
|
|
|
|
|
|
sub V { |
|
120
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
121
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
# pop the values |
|
124
|
0
|
|
|
|
|
|
my $i = $ip->spop; |
|
125
|
0
|
|
|
|
|
|
my $r = $ip->spop; |
|
126
|
|
|
|
|
|
|
|
|
127
|
0
|
|
|
|
|
|
my $c = cplx($r, $i); |
|
128
|
0
|
|
|
|
|
|
$ip->spush( $c->abs ); |
|
129
|
|
|
|
|
|
|
} |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# -- display |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# |
|
135
|
|
|
|
|
|
|
# O( $r, $i ) |
|
136
|
|
|
|
|
|
|
# |
|
137
|
|
|
|
|
|
|
# output complex number $r+i*$i |
|
138
|
|
|
|
|
|
|
# |
|
139
|
|
|
|
|
|
|
sub O { |
|
140
|
0
|
|
|
0
|
1
|
|
my ($self, $interp) = @_; |
|
141
|
0
|
|
|
|
|
|
my $ip = $interp->get_curip; |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# pop the values |
|
144
|
0
|
|
|
|
|
|
my $i = $ip->spop; |
|
145
|
0
|
|
|
|
|
|
my $r = $ip->spop; |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# print the complex |
|
148
|
0
|
|
|
|
|
|
my $c = cplx($r, $i); |
|
149
|
0
|
|
|
|
|
|
print $c; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
1; |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
__END__ |