@@ -74,7 +74,7 @@ =head2 isPrime
74
74
75
75
=cut
76
76
77
- loadMacros(' MathObjects.pl' );
77
+ loadMacros(' PGbasicmacros.pl ' , ' MathObjects.pl' );
78
78
79
79
sub _contextInteger_init { context::Integer::Init() }
80
80
@@ -124,7 +124,7 @@ sub Init {
124
124
sub _divisor {
125
125
my $power = abs(shift );
126
126
my $a = abs(shift );
127
- $self -> Error(" Cannot perform divisor function on Zero" ) if $a == 0;
127
+ Value:: Error(' Cannot perform divisor function on Zero' ) if $a == 0;
128
128
$result = 1;
129
129
$sqrt_a = int (sqrt ($a ));
130
130
for (my $i = 2; $i < $sqrt_a ; $i ++) {
@@ -146,17 +146,17 @@ sub _divisor {
146
146
sub _getPrimesInRange {
147
147
my $index = shift ;
148
148
my $end = shift ;
149
- $self -> Error(" Start of range must be a positive number." ) if $index < 0;
150
- $self -> Error(" End of range must be greater than or equal to 2" ) if $end < 2;
151
- $self -> Error(" Start or range must be before end of range" ) if $index > $end ;
149
+ Value:: Error(' Start of range must be a positive number.' ) if $index < 0;
150
+ Value:: Error(' End of range must be greater than or equal to 2' ) if $end < 2;
151
+ Value:: Error(' Start of range must be before end of range' ) if $index > $end ;
152
152
@primes = ();
153
153
154
154
# consider switching to set upper limit and static array of primes
155
155
156
156
push (@primes , 2) if $index <= 2;
157
157
# ensure index is odd
158
158
$index ++ if $index % 2 == 0;
159
- while ($index < $end ) {
159
+ while ($index <= $end ) {
160
160
push (@primes , $index ) if context::Integer::Function::Numeric::isPrime($index );
161
161
$index += 2;
162
162
}
@@ -172,8 +172,8 @@ package context::Integer::Function::Numeric;
172
172
#
173
173
sub primeFactorization {
174
174
my $a = abs(shift );
175
- $self -> Error(" Cannot factor Zero into primes." ) if $a == 0;
176
- $self -> Error(" Cannot factor One into primes." ) if $a == 1;
175
+ Value:: Error(' Cannot factor Zero into primes.' ) if $a == 0;
176
+ Value:: Error(' Cannot factor One into primes.' ) if $a == 1;
177
177
178
178
my %factors ;
179
179
my $n = $a ;
@@ -200,7 +200,7 @@ sub primeFactorization {
200
200
#
201
201
sub phi {
202
202
my $a = abs(shift );
203
- $self -> Error(" Cannot phi on Zero." ) if $a == 0;
203
+ Value:: Error(' Cannot phi on Zero.' ) if $a == 0;
204
204
$result = $a ;
205
205
$n = $a ;
206
206
for (my $i = 2; ($i **2) <= $n ; $i ++) {
@@ -235,9 +235,8 @@ sub isPrime {
235
235
sub randomPrime {
236
236
my ($start , $end ) = @_ ;
237
237
my @primes = context::Integer::_getPrimesInRange($start , $end );
238
- $self -> Error(" Could not find any prime numbers in range." ) if $#primes == 0;
239
- my $primeIndex = $main::PG_random_generator -> random(0, ($#primes - 1), 1);
240
- return $primes [$primeIndex ];
238
+ Value::Error(' Could not find any prime numbers in range.' ) unless @primes ;
239
+ return main::list_random(@primes );
241
240
}
242
241
243
242
package context::Integer::Function::Numeric2 ;
0 commit comments