Add some math functions
This commit is contained in:
parent
39be8fdfd6
commit
87a4340aba
|
|
@ -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;
|
||||||
Loading…
Reference in New Issue