diff --git a/PerlRPG/Math.pm b/PerlRPG/Math.pm new file mode 100644 index 0000000..4c35530 --- /dev/null +++ b/PerlRPG/Math.pm @@ -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;