From 87a4340aba12b360d3ea5849797b11525b08bf30 Mon Sep 17 00:00:00 2001 From: Ryan Shepherd Date: Thu, 4 Oct 2018 15:25:36 -0400 Subject: [PATCH] Add some math functions --- PerlRPG/Math.pm | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 PerlRPG/Math.pm 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;