[system] / trunk / pg / macros / PGauxiliaryFunctions.pl Repository:
ViewVC logotype

Diff of /trunk/pg/macros/PGauxiliaryFunctions.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1071 Revision 1080
1#!/usr/local/bin/webwork-perl 1
2sub _PGauxiliaryFunctions_init { 2sub _PGauxiliaryFunctions_init {
3 3
4} 4}
5 5
6sub tan { 6sub tan {
82 82
83sub max { 83sub max {
84 84
85 my $maxVal = shift; 85 my $maxVal = shift;
86 my @input = @_; 86 my @input = @_;
87 87
88 foreach my $num (@input) { 88 foreach my $num (@input) {
89 $maxVal = $num if ($maxVal < $num); 89 $maxVal = $num if ($maxVal < $num);
90 } 90 }
91 91
92 $maxVal; 92 $maxVal;
93 93
94} 94}
95 95
96sub min { 96sub min {
97 97
98 my $minVal = shift; 98 my $minVal = shift;
99 my @input = @_; 99 my @input = @_;
100 100
101 foreach my $num (@input) { 101 foreach my $num (@input) {
102 $minVal = $num if ($minVal > $num); 102 $minVal = $num if ($minVal > $num);
103 } 103 }
104 104
105 $minVal; 105 $minVal;
106 106
107} 107}
108 108
109#round added 6/12/2000 by David Etlinger 109#round added 6/12/2000 by David Etlinger
110sub round { 110sub round {
111 my $input = shift; 111 my $input = shift;
112 my $out; 112 my $out;
147 147
148# greatest common factor 148# greatest common factor
149# takes in two scalar values and uses the Euclidean Algorithm to return the gcf 149# takes in two scalar values and uses the Euclidean Algorithm to return the gcf
150#VS 6/29/2000 150#VS 6/29/2000
151 151
152sub gcf { 152sub gcf {
153 my $a = abs(shift); # absolute values because this will yield the same gcd, 153 my $a = abs(shift); # absolute values because this will yield the same gcd,
154 my $b = abs(shift); # but allows use of the mod operation 154 my $b = abs(shift); # but allows use of the mod operation
155 155
156 # reorder such that b is the smaller number 156 # reorder such that b is the smaller number
157 if ($a < $b) { 157 if ($a < $b) {
158 my $temp = $a; 158 my $temp = $a;
159 $a = $b; 159 $a = $b;
160 $b = $temp; 160 $b = $temp;
161 } 161 }
162 162
163 return $a if $b == 0; 163 return $a if $b == 0;
164 164
165 my $q = int($a/$b); # quotient 165 my $q = int($a/$b); # quotient
166 my $r = $a % $b; # remainder 166 my $r = $a % $b; # remainder
167 167
168 return $b if $r == 0; 168 return $b if $r == 0;
169 169
170 my $tempR = $r; 170 my $tempR = $r;
171 171
172 while ($r != 0) { 172 while ($r != 0) {
173 173
174 #keep track of what $r was in the last loop, as this is the value 174 #keep track of what $r was in the last loop, as this is the value
175 #we will want when $r is set to 0 175 #we will want when $r is set to 0
176 $tempR = $r; 176 $tempR = $r;
177 177
178 $a = $b; 178 $a = $b;
179 $b = $r; 179 $b = $r;
220 my @frac = ($num, $denom); 220 my @frac = ($num, $denom);
221 @frac; 221 @frac;
222} 222}
223 223
224 224
225# takes a number and fixed object, as in "$a x" and formats 225# takes a number and fixed object, as in "$a x" and formats
226# to account for when $a = 0, 1, -1 226# to account for when $a = 0, 1, -1
227# Usage: format($scalar, "quoted string"); 227# Usage: format($scalar, "quoted string");
228# Example: format(-1, "\pi") returns "-\pi" 228# Example: format(-1, "\pi") returns "-\pi"
229# VS 8/1/2000 - slight adaption of code from T. Shemanske of Dartmouth College 229# VS 8/1/2000 - slight adaption of code from T. Shemanske of Dartmouth College
230sub preformat { 230sub preformat {
231 my $num = shift; 231 my $num = shift;
232 my $obj = shift; 232 my $obj = shift;
233 my $out; 233 my $out;
234 234
235 235
236 if ($num == 0) { return 0; } 236 if ($num == 0) { return 0; }
237 elsif ($num == 1) { return $obj; } 237 elsif ($num == 1) { return $obj; }
238 elsif ($num == -1) { return "-".$obj; } 238 elsif ($num == -1) { return "-".$obj; }
239 239
240 return $num.$obj; 240 return $num.$obj;

Legend:
Removed from v.1071  
changed lines
  Added in v.1080

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9