@@ -74,7 +74,7 @@ =head2 isPrime
7474
7575=cut
7676
77- loadMacros(' MathObjects.pl' );
77+ loadMacros(' PGbasicmacros.pl ' , ' MathObjects.pl' );
7878
7979sub _contextInteger_init { context::Integer::Init() }
8080
@@ -124,7 +124,7 @@ sub Init {
124124sub _divisor {
125125 my $power = abs(shift );
126126 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;
128128 $result = 1;
129129 $sqrt_a = int (sqrt ($a ));
130130 for (my $i = 2; $i < $sqrt_a ; $i ++) {
@@ -146,17 +146,17 @@ sub _divisor {
146146sub _getPrimesInRange {
147147 my $index = shift ;
148148 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 ;
152152 @primes = ();
153153
154154 # consider switching to set upper limit and static array of primes
155155
156156 push (@primes , 2) if $index <= 2;
157157 # ensure index is odd
158158 $index ++ if $index % 2 == 0;
159- while ($index < $end ) {
159+ while ($index <= $end ) {
160160 push (@primes , $index ) if context::Integer::Function::Numeric::isPrime($index );
161161 $index += 2;
162162 }
@@ -172,8 +172,8 @@ package context::Integer::Function::Numeric;
172172#
173173sub primeFactorization {
174174 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;
177177
178178 my %factors ;
179179 my $n = $a ;
@@ -200,7 +200,7 @@ sub primeFactorization {
200200#
201201sub phi {
202202 my $a = abs(shift );
203- $self -> Error(" Cannot phi on Zero." ) if $a == 0;
203+ Value:: Error(' Cannot phi on Zero.' ) if $a == 0;
204204 $result = $a ;
205205 $n = $a ;
206206 for (my $i = 2; ($i **2) <= $n ; $i ++) {
@@ -235,9 +235,8 @@ sub isPrime {
235235sub randomPrime {
236236 my ($start , $end ) = @_ ;
237237 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 );
241240}
242241
243242package context::Integer::Function::Numeric2 ;
0 commit comments