2 # infobot copyright (C) kevin lenzo 1997-98
33 my($locMsg) = $message;
35 if ($message =~ /^\s*$/) {
39 foreach (keys %digits) {
40 $locMsg =~ s/$_/$digits{$_}/g;
43 while ($locMsg =~ /(exp ([\w\d]+))/) {
44 my($exp, $val) = ($1, exp $2);
45 $locMsg =~ s/$exp/+$val/g;
48 while ($locMsg =~ /(hex2dec\s*([0-9A-Fa-f]+))/) {
49 my($exp, $val) = ($1, hex $2);
50 $locMsg =~ s/$exp/+$val/g;
53 if ($locMsg =~ /^\s*(dec2hex\s*(\d+))\s*\?*/) {
54 my ($exp, $val) = ($1, sprintf("%x", "$2"));
55 $locMsg =~ s/$exp/+$val/g;
59 $locMsg =~ s/\be\b/$e/;
61 while ($locMsg =~ /(log\s*((\d+\.?\d*)|\d*\.?\d+))\s*/) {
62 my ($exp, $res) = ($1, $2);
63 my $val = ($res) ? log($res) : "Infinity";
64 $locMsg =~ s/$exp/+$val/g;
67 while ($locMsg =~ /(bin2dec ([01]+))/) {
69 my $val = join ("", unpack("B*",$2)) ;
70 $locMsg =~ s/$exp/+$val/g;
73 while ($locMsg =~ /(dec2bin (\d+))/) {
75 my $val = join('', unpack('B*', pack('N',$2)));
77 $locMsg =~ s/$exp/+$val/g;
81 s/\bpi\b/3.14159265/g;
84 s/\bdiv(ided by)? /\/ /g;
88 s/\bto\s+(\d+)(r?st|nd|rd|th)?( power)?/\*\*$1 /ig;
89 s/\bpercent of/*0.01*/ig;
93 s/\bsquare root of (\d+)/$1 ** 0.5 /ig;
94 s/\bcubed? root of (\d+)/$1 **(1.0\/3.0) /ig;
96 s/(bit(-| )?)?xor(\'?e?d( with))?/\^/g;
97 s/(bit(-| )?)?or(\'?e?d( with))?/\|/g;
98 s/bit(-| )?and(\'?e?d( with))?/\& /g;
102 # what the hell is this shit?
103 if (($locMsg =~ /^\s*[-\d*+\s()\/^\.\|\&\*\!]+\s*$/)
104 && ($locMsg !~ /^\s*\(?\d+\.?\d*\)?\s*$/)
105 && ($locMsg !~ /^\s*$/)
106 && ($locMsg !~ /^\s*[( )]+\s*$/)
107 && ($locMsg =~ /\d+/)
109 $locMsg =~ s/([0-9]+\.[0-9]+(\.[0-9]+)+)/"$1"/g;
110 $locMsg = eval($locMsg);
112 if (defined $locMsg and $locMsg =~ /^[-+\de\.]+$/) {
113 $locMsg = sprintf("%1.12f", $locMsg);
114 $locMsg =~ s/\.?0+$//;
116 if (length $locMsg > 30) {
117 $locMsg = "a number with quite a few digits...";
120 if (defined $locMsg) {
121 &FIXME("math: locMsg => '$locMsg'...");
123 &status("math: could not really compute.");
131 if (defined $locMsg and $locMsg ne $message) {