line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Math::FractionDemo; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# Math::Fraction v.53b (2 Feb 1998) Test Script |
4
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
1212
|
use Math::Fraction qw(:DEFAULT :STR_NUM); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
173
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
require Exporter; |
8
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
1223
|
|
9
|
|
|
|
|
|
|
$VERSION = ".53"; |
10
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
11
|
|
|
|
|
|
|
@EXPORT = qw(frac_calc frac_demo); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub frac_calc { |
14
|
0
|
|
|
0
|
1
|
0
|
local $^W = 0; |
15
|
|
|
|
|
|
|
sub pevel; |
16
|
|
|
|
|
|
|
|
17
|
0
|
|
|
|
|
0
|
local $f1 = Math::Fraction->new(1,2); |
18
|
0
|
|
|
|
|
0
|
local $f2 = Math::Fraction->new(1,3); |
19
|
0
|
|
|
|
|
0
|
local $f3 = Math::Fraction->new(5,3,MIXED); |
20
|
0
|
|
|
|
|
0
|
local $f4 = Math::Fraction->new(1,3,NO_REDUCE); |
21
|
|
|
|
|
|
|
|
22
|
0
|
|
|
|
|
0
|
print <<'---'; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Fraction "Calculator" for testing the Fraction Module. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Simply enter in any valid perl expression. The results are printed |
27
|
|
|
|
|
|
|
to the screen and stored the variable $ans for referring back to. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Examples: |
30
|
|
|
|
|
|
|
>5+5 |
31
|
|
|
|
|
|
|
10 |
32
|
|
|
|
|
|
|
>$ans*2 |
33
|
|
|
|
|
|
|
20 |
34
|
|
|
|
|
|
|
>frac(1,2) |
35
|
|
|
|
|
|
|
1/2 |
36
|
|
|
|
|
|
|
>$ans*frac(1,2) |
37
|
|
|
|
|
|
|
1/4 |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
To see a demonstration of the fraction module features type in "frac_demo". |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
--- |
42
|
0
|
|
|
|
|
0
|
print "Pre-Set: \$f1=$f1 \$f2=$f2 \$f3=$f3 \$f4=$f4(NO_REDUCE)\n"; |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
|
|
0
|
print ">"; |
45
|
0
|
|
|
|
|
0
|
local $ans; |
46
|
0
|
|
|
|
|
0
|
while(<>) {$ans = eval; print $@; print "$ans\n>";} |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub pevel { |
50
|
47
|
|
|
47
|
0
|
3077
|
$ans = eval $_[0]; |
51
|
47
|
50
|
|
|
|
1544
|
if (not $test) { |
|
|
50
|
|
|
|
|
|
52
|
0
|
|
|
|
|
0
|
print $output "$space>$_[0]\n"; |
53
|
0
|
|
|
|
|
0
|
print $output "$space $ans\n"; |
54
|
|
|
|
|
|
|
} elsif ($test eq 'TESTCREATE') { |
55
|
0
|
|
|
|
|
0
|
print $output " pevel q~$_[0]~, q~$ans~;\n"; |
56
|
|
|
|
|
|
|
} else { |
57
|
47
|
100
|
|
|
|
223
|
if ("$ans" eq "$_[1]") { |
58
|
34
|
|
|
|
|
71
|
print "ok\n" |
59
|
|
|
|
|
|
|
} else { |
60
|
13
|
|
|
|
|
932
|
print STDERR qq~Test: $_[0]\n"$ans" ne\n"$_[1]"\n~; |
61
|
13
|
|
|
|
|
40
|
print "not ok\n" |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub evelp { |
67
|
27
|
|
|
27
|
0
|
2124
|
eval $_[0]; |
68
|
27
|
50
|
|
|
|
108
|
if (not $test) { |
|
|
50
|
|
|
|
|
|
69
|
0
|
|
|
|
|
0
|
print $output "$space>$_[0]\n"; |
70
|
|
|
|
|
|
|
} elsif ($test eq 'TESTCREATE') { |
71
|
0
|
|
|
|
|
0
|
print $output " evelp q~$_[0]~;\n"; |
72
|
|
|
|
|
|
|
} else { |
73
|
27
|
|
|
|
|
49
|
print "ok\n" |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub pause { |
78
|
6
|
50
|
|
6
|
0
|
29
|
if (not $test) { |
|
|
50
|
|
|
|
|
|
79
|
0
|
0
|
|
|
|
0
|
if ($output eq STDOUT) { |
80
|
0
|
|
|
|
|
0
|
print "Press Enter to go on\n"; |
81
|
0
|
|
|
|
|
0
|
; |
82
|
0
|
|
|
|
|
0
|
Math::Fraction->load_set(DEFAULT); |
83
|
|
|
|
|
|
|
} else { |
84
|
0
|
|
|
|
|
0
|
print $output "$space\n"; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
} elsif ($test eq 'TESTCREATE') { |
87
|
0
|
|
|
|
|
0
|
print $output " pause;\n"; |
88
|
|
|
|
|
|
|
} else { |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub s { |
93
|
5
|
100
|
|
5
|
0
|
6
|
my @ret = map {$_ eq undef() ? 'undef' : $_} @_; |
|
25
|
|
|
|
|
48
|
|
94
|
5
|
|
|
|
|
39
|
"@ret"; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub frac_demo { |
98
|
1
|
|
|
1
|
1
|
6
|
local $^W = 0; |
99
|
1
|
|
50
|
|
|
8
|
local($output) = $_[0] || STDOUT; |
100
|
1
|
|
|
|
|
3
|
local($test,$space); |
101
|
1
|
50
|
33
|
|
|
7
|
if ($_[1] eq 'TEST' || $_[1] eq 'TESTCREATE') { |
102
|
1
|
|
|
|
|
4
|
$test = $_[1] |
103
|
|
|
|
|
|
|
} else { |
104
|
0
|
|
|
|
|
0
|
$space = " "x$_[1]; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
|
|
4
|
local($f1,$f2); |
108
|
|
|
|
|
|
|
|
109
|
1
|
50
|
|
|
|
7
|
my $set = Math::Fraction->temp_set unless $test; |
110
|
|
|
|
|
|
|
|
111
|
1
|
50
|
|
|
|
28
|
print "1..74\n" if $test eq 'TEST'; |
112
|
|
|
|
|
|
|
|
113
|
1
|
|
|
|
|
6
|
pevel q~frac(1, 3)~, q~1/3~; |
114
|
1
|
|
|
|
|
4
|
pevel q~frac(4, 3, MIXED)~, q~1 1/3~; |
115
|
1
|
|
|
|
|
3
|
pevel q~frac(1, 1, 3)~, q~4/3~; |
116
|
1
|
|
|
|
|
3
|
pevel q~frac(1, 1, 3, MIXED)~, q~1 1/3~; |
117
|
1
|
|
|
|
|
3
|
pevel q~frac(10)~, q~10/1~; |
118
|
1
|
|
|
|
|
4
|
pevel q~frac(10, MIXED)~, q~10~; |
119
|
1
|
|
|
|
|
3
|
pevel q~frac(.66667)~, q~2/3~; |
120
|
1
|
|
|
|
|
4
|
pevel q~frac(1.33333, MIXED)~, q~1 1/3~; |
121
|
1
|
|
|
|
|
6
|
pevel q~frac("5/6")~, q~5/6~; |
122
|
1
|
|
|
|
|
4
|
pevel q~frac("1 2/3")~, q~5/3~; |
123
|
1
|
|
|
|
|
3
|
pevel q~frac(10, 20, NO_REDUCE)~, q~10/20~; |
124
|
1
|
|
|
|
|
4
|
pause; |
125
|
1
|
|
|
|
|
4
|
evelp q~$f1=frac(2,3); $f2=frac(4,5);~; |
126
|
1
|
|
|
|
|
4
|
pevel q~$f1 + $f2~, q~22/15~; |
127
|
1
|
|
|
|
|
5
|
pevel q~$f1 * $f2~, q~8/15~; |
128
|
1
|
|
|
|
|
2
|
pevel q~$f1 + 1.6667~, q~7/3~; |
129
|
1
|
|
|
|
|
3
|
evelp q~$f2->modify_tag(MIXED)~; |
130
|
1
|
|
|
|
|
3
|
pevel q~$f2 + 10~, q~10 4/5~; |
131
|
1
|
|
|
|
|
3
|
pevel q~frac($ans, NORMAL) # trick to create a new fraction with different tags~, q~54/5~; |
132
|
1
|
|
|
|
|
3
|
pevel q~$f1 + $f2 # Add two unlikes it goes to default mode~, q~22/15~; |
133
|
1
|
|
|
|
|
4
|
pevel q~$f1**1.2~, q~229739670999407/373719281884655~; |
134
|
1
|
|
|
|
|
3
|
pevel q~$f1->num**1.2~, q~0.614738607654485~; |
135
|
1
|
|
|
|
|
3
|
pevel q~frac(1,2)+frac(2,5)~, q~9/10~; |
136
|
1
|
|
|
|
|
4
|
pause; |
137
|
1
|
|
|
|
|
4
|
evelp q~$f1=frac(5,3,NORMAL); $f2=frac(7,5);~; |
138
|
1
|
|
|
|
|
14
|
pevel q~"$f1 $f2"~, q~5/3 7/5~; |
139
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_tag(MIXED)~; |
140
|
1
|
|
|
|
|
4
|
pevel q~"$f1 $f2"~, q~5/3 1 2/5~; |
141
|
1
|
|
|
|
|
2
|
pevel q~$f1 = frac("3267893629762/32678632179820")~, q~3267893629762/32678632179820~; |
142
|
1
|
|
|
|
|
3
|
pevel q~$f2 = frac("5326875886785/76893467996910")~, q~5326875886785/76893467996910~; |
143
|
1
|
|
|
|
|
3
|
pevel q~$f1->is_tag(BIG).",".$f2->is_tag(BIG) # Notice how neither of them is BIG ~, q~0,0~; |
144
|
1
|
|
|
|
|
2
|
pevel q~$f1+$f2~, q~21267734600460495169085706/125638667885089122116217810~; |
145
|
1
|
|
|
|
|
5
|
pevel q~$ans->is_tag(BIG) # But this answer is.~, q~1~; |
146
|
1
|
|
|
|
|
3
|
pevel q~$f1*$f2~, q~1740766377695750621849517/251277335770178244232435620~; |
147
|
1
|
|
|
|
|
5
|
pevel q~$ans->is_tag(BIG) # And so is this one.~, q~1~; |
148
|
1
|
|
|
|
|
4
|
pause; |
149
|
1
|
|
|
|
|
3
|
pevel q~$f1 = frac("3267893629762/32678632179820", BIG)~, q~3267893629762/32678632179820~; |
150
|
1
|
|
|
|
|
3
|
pevel q~$f1->is_tag(BIG) # Notice how the big tag had no effect.~, q~0~; |
151
|
1
|
|
|
|
|
3
|
evelp q~$f1->modify_tag(NO_AUTO, BIG)~; |
152
|
1
|
|
|
|
|
4
|
pevel q~$f1->is_tag(BIG) # But now it does. You have to turn off AUTO.~, q~1~; |
153
|
1
|
|
|
|
|
2
|
pevel q~$f1->num~, q~.10000093063197482237806917498797382196606~; |
154
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_digits(15)~; |
155
|
1
|
|
|
|
|
4
|
pevel q~$f1->num~, q~.1000009306319748~; |
156
|
1
|
|
|
|
|
4
|
pevel q~$f1 = frac("0.1231231234564564564564564564561234567891234567891234")~, q~13680347037037036999999999999963000037/111111111000000000000000000000000000000~; |
157
|
1
|
|
|
|
|
5
|
evelp q~Math::Fraction->modify_digits(65)~; |
158
|
1
|
|
|
|
|
4
|
pevel q~$f1->num~, q~.123123123456456456456456456456123456789123456789123456789123456789~; |
159
|
1
|
|
|
|
|
4
|
pause; |
160
|
1
|
|
|
|
|
3
|
evelp q~$f1 = frac(7,5);~; |
161
|
1
|
|
|
|
|
2
|
evelp q~$f2 = frac("3267893629762/32678632179820", NO_AUTO, BIG)~; |
162
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_tag(MIXED); Math::Fraction->modify_digits(60)~; |
163
|
1
|
|
|
|
|
3
|
pevel q~"$f1 ".$f2->num~, q~1 2/5 .1000009306319748223780691749879738219660647769485035912494771~; |
164
|
1
|
|
|
|
|
4
|
evelp q~Math::Fraction->load_set(DEFAULT)~; |
165
|
1
|
|
|
|
|
2
|
pevel q~"$f1 ".$f2->num~, q~7/5 .10000093063197482237806917498797382196606~; |
166
|
1
|
|
|
|
|
2
|
evelp q~Math::Fraction->modify_digits(25)~; |
167
|
1
|
|
|
|
|
3
|
pevel q~"$f1 ".$f2->num~, q~7/5 .10000093063197482237806917~; |
168
|
1
|
|
|
|
|
4
|
evelp q~$s = Math::Fraction->temp_set~; |
169
|
1
|
|
|
|
|
2
|
evelp q~Math::Fraction->modify_tag(MIXED); Math::Fraction->modify_digits(15)~; |
170
|
1
|
|
|
|
|
2
|
pevel q~"$f1 ".$f2->num~, q~1 2/5 .1000009306319748~; |
171
|
1
|
|
|
|
|
4
|
evelp q~Math::Fraction->temp_set($s)~; |
172
|
1
|
|
|
|
|
2
|
pevel q~Math::Fraction->exists_set($s)~, q~~; |
173
|
1
|
|
|
|
|
3
|
pevel q~"$f1 ".$f2->num # Notice how it goes back to the previous settings.~, q~7/5 .10000093063197482237806917~; |
174
|
1
|
|
|
|
|
4
|
pause; |
175
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->name_set('temp1')~; |
176
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_tag(MIXED, NO_AUTO)~; |
177
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_digits(60)~; |
178
|
1
|
|
|
|
|
10
|
pevel q~&s(Math::Fraction->tags, Math::Fraction->digits)~, q~MIXED REDUCE SMALL NO_AUTO 60~; |
179
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->save_set # If no name is given it will be saved via~; |
180
|
1
|
|
|
|
|
3
|
evelp q~ # its given name~; |
181
|
1
|
|
|
|
|
2
|
evelp q~Math::Fraction->load_set(DEFAULT)~; |
182
|
1
|
|
|
|
|
3
|
pevel q~&s(Math::Fraction->tags, Math::Fraction->digits)~, q~NORMAL REDUCE SMALL AUTO undef~; |
183
|
1
|
|
|
|
|
2
|
pevel q~&s(Math::Fraction->tags('temp1'), Math::Fraction->digits('temp1'))~, q~MIXED REDUCE SMALL NO_AUTO 60~; |
184
|
1
|
|
|
|
|
3
|
evelp q~ # ^^ Notice how this lets you preview other sets with out loading them.~; |
185
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->load_set(DEFAULT)~; |
186
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->use_set('temp1')~; |
187
|
1
|
|
|
|
|
3
|
evelp q~Math::Fraction->modify_tag(NO_REDUCE)~; |
188
|
1
|
|
|
|
|
3
|
pevel q~&s(Math::Fraction->tags, Math::Fraction->digits)~, q~MIXED NO_REDUCE SMALL NO_AUTO 60~; |
189
|
1
|
|
|
|
|
2
|
pevel q~&s(Math::Fraction->tags('temp1'), Math::Fraction->digits('temp1'))~, q~MIXED NO_REDUCE SMALL NO_AUTO 60~; |
190
|
1
|
|
|
|
|
2
|
evelp q~ # ^^ Notice how this also modifies the temp1 tag becuase it is being used~; |
191
|
1
|
|
|
|
|
3
|
evelp q~ # if it was just loaded it would not do this becuase there is no link.~; |
192
|
1
|
|
|
|
|
3
|
pause; |
193
|
|
|
|
|
|
|
|
194
|
1
|
50
|
|
|
|
3
|
Math::Fraction->del_set('temp1') unless $test; |
195
|
1
|
50
|
|
|
|
3
|
Math::Fraction->temp_set($set) unless $test; |
196
|
|
|
|
|
|
|
|
197
|
1
|
50
|
|
|
|
4
|
print "END\n" if $test eq 'TEST'; |
198
|
|
|
|
|
|
|
|
199
|
1
|
|
|
|
|
|
return undef; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
1; |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
__END__ |