2 # infobot copyright (C) kevin lenzo 1997-98
5 if (&IsParam("useStrict")) { use strict; }
31 my($locMsg) = $message;
33 if ($message =~ /^\s*$/) {
37 foreach (keys %digits) {
38 $locMsg =~ s/$_/$digits{$_}/g;
41 while ($locMsg =~ /(exp ([\w\d]+))/) {
42 my($exp, $val) = ($1, exp $2);
43 $locMsg =~ s/$exp/+$val/g;
46 while ($locMsg =~ /(hex2dec\s*([0-9A-Fa-f]+))/) {
47 my($exp, $val) = ($1, hex $2);
48 $locMsg =~ s/$exp/+$val/g;
51 if ($locMsg =~ /^\s*(dec2hex\s*(\d+))\s*\?*/) {
52 my ($exp, $val) = ($1, sprintf("%x", "$2"));
53 $locMsg =~ s/$exp/+$val/g;
57 $locMsg =~ s/\be\b/$e/;
59 while ($locMsg =~ /(log\s*((\d+\.?\d*)|\d*\.?\d+))\s*/) {
60 my ($exp, $res) = ($1, $2);
61 my $val = ($res) ? log($res) : "Infinity";
62 $locMsg =~ s/$exp/+$val/g;
65 while ($locMsg =~ /(bin2dec ([01]+))/) {
67 my $val = join ("", unpack("B*",$2)) ;
68 $locMsg =~ s/$exp/+$val/g;
71 while ($locMsg =~ /(dec2bin (\d+))/) {
73 my $val = join('', unpack('B*', pack('N',$2)));
75 $locMsg =~ s/$exp/+$val/g;
82 s/\bdiv(ided by)? /\/ /g;
86 s/\bto\s+(\d+)(r?st|nd|rd|th)?( power)?/\*\*$1 /ig;
87 s/\bpercent of/*0.01*/ig;
91 s/\bsquare root of (\d+)/$1 ** 0.5 /ig;
92 s/\bcubed? root of (\d+)/$1 **(1.0\/3.0) /ig;
94 s/(bit(-| )?)?xor(\'?e?d( with))?/\^/g;
95 s/(bit(-| )?)?or(\'?e?d( with))?/\|/g;
96 s/bit(-| )?and(\'?e?d( with))?/\& /g;
100 # what the hell is this shit?
101 if (($locMsg =~ /^\s*[-\d*+\s()\/^\.\|\&\*\!]+\s*$/)
102 && ($locMsg !~ /^\s*\(?\d+\.?\d*\)?\s*$/)
103 && ($locMsg !~ /^\s*$/)
104 && ($locMsg !~ /^\s*[( )]+\s*$/)
105 && ($locMsg =~ /\d+/)
107 $locMsg =~ s/([0-9]+\.[0-9]+(\.[0-9]+)+)/"$1"/g;
108 $locMsg = eval($locMsg);
110 if (defined $locMsg and $locMsg =~ /^[-+\de\.]+$/) {
111 $locMsg = sprintf("%1.12f", $locMsg);
112 $locMsg =~ s/\.?0+$//;
114 if (length $locMsg > 30) {
115 $locMsg = "a number with quite a few digits...";
118 if (defined $locMsg) {
119 &DEBUG("math: locMsg => '$locMsg'... FIXME");
121 &status("math: could not really compute.");
129 if (defined $locMsg and $locMsg ne $message) {