1 #**************************************************************************
2 # Copyright (C) 2006 by Michael Andreen <harvATruinDOTnu> *
4 # This program is free software; you can redistribute it and/or modify *
5 # it under the terms of the GNU General Public License as published by *
6 # the Free Software Foundation; either version 2 of the License, or *
7 # (at your option) any later version. *
9 # This program is distributed in the hope that it will be useful, *
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 # GNU General Public License for more details. *
14 # You should have received a copy of the GNU General Public License *
15 # along with this program; if not, write to the *
16 # Free Software Foundation, Inc., *
17 # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 #**************************************************************************/
23 use CGI qw{:standard};
26 our @ISA = qw/Exporter/;
28 our @EXPORT = qw/min max parseValue prettyValue pa_xp/;
32 return ($x > $y ? $y : $x);
37 return ($x < $y ? $y : $x);
41 if (defined $_[0] && $_[0] =~ /^(-?\d+(?:\.\d+)?)([khMG])?$/){
42 return $1 unless defined $2;
43 return $1*100 if $2 eq 'h';
44 return $1*1000 if $2 eq 'k';
45 return $1*1000000 if $2 eq 'M';
46 return $1*1000000000 if $2 eq 'G';
52 my ($value,$decimals) = @_;
53 return sprintf('%.3e',$value) if $value > 1000000000000000;
55 my @units = ('k','M','G','T');
56 for (my $i = 0; $value >= 1000 && $i < 4;$i++){
60 unless (defined $decimals){
62 $decimals = '.1' if $value < 100 && $unit;
63 $decimals = '.2' if $value < 10 && $unit;
66 return sprintf('%'.$decimals.'f%s', $value,$unit);
70 my ($roids,$ascore,$avalue,$tscore,$tvalue) = @_;
71 my $bravery = (max(0,min(2,$tscore/$ascore)-0.2)) * (min(2,$tvalue/$avalue)-0.1);
72 return int(max($roids * 10 * $bravery,0))