Add some math functions

This commit is contained in:
Ryan Shepherd 2018-10-04 15:25:36 -04:00
parent 39be8fdfd6
commit 87a4340aba
1 changed files with 23 additions and 0 deletions

23
PerlRPG/Math.pm Normal file
View File

@ -0,0 +1,23 @@
package PerlRPG::Math;
use strict;
require Exporter;
use vars qw/@ISA @EXPORT @EXPORT_OK/;
@ISA = qw/Exporter/;
@EXPORT = qw/Constrain MIN MAX/;
@EXPORT_OK = ();
sub MIN {
return ($_[0] > $_[1] ? $_[0] : $_[1]);
}
sub MAX {
return ($_[0] > $_[1] ? $_[1] : $_[0]);
}
sub Constrain {
my($val, $min, $max)=@_;
return MAX(MIN($val, $min),$max);
}
1;