Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,26 @@
#!/usr/bin/perl -w
use strict ;
sub expon {
my ( $base , $expo ) = @_ ;
if ( $expo == 0 ) {
return 1 ;
}
elsif ( $expo == 1 ) {
return $base ;
}
elsif ( $expo > 1 ) {
my $prod = 1 ;
foreach my $n ( 0..($expo - 1) ) {
$prod *= $base ;
}
return $prod ;
}
elsif ( $expo < 0 ) {
return 1 / ( expon ( $base , -$expo ) ) ;
}
}
print "3 to the power of 10 as a function is " . expon( 3 , 10 ) . " !\n" ;
print "3 to the power of 10 as a builtin is " . 3**10 . " !\n" ;
print "5.5 to the power of -3 as a function is " . expon( 5.5 , -3 ) . " !\n" ;
print "5.5 to the power of -3 as a builtin is " . 5.5**-3 . " !\n" ;

View file

@ -0,0 +1,13 @@
sub ex {
my($base,$exp) = @_;
die "Exponent '$exp' must be an integer!" if $exp != int($exp);
return 1 if $exp == 0;
($base, $exp) = (1/$base, -$exp) if $exp < 0;
my $c = 1;
while ($exp > 1) {
$c *= $base if $exp % 2;
$base *= $base;
$exp >>= 1;
}
$base * $c;
}