Revert my bignum change.

master
Gabriel Weinberg 2013-12-25 10:14:14 -05:00
parent 028d4dc5d4
commit 597e3c0e39
1 changed files with 47 additions and 50 deletions

View File

@ -1,6 +1,7 @@
package DDG::Goodie::Calculator;
use DDG::Goodie;
use bignum;
zci is_cached => 1;
zci answer_type => "calc";
@ -92,60 +93,56 @@ handle query_nowhitespace => sub {
# 2011.11.09 fix for 21 + 15 x 0 + 5
$tmp_expr =~ s/(?<!\.)(?<![0-9])0([1-9])/$1/;
{
use bignum;
eval {
$tmp_result = eval($tmp_expr);
};
eval {
$tmp_result = eval($tmp_expr);
};
# 0-9 check for http://yegg.duckduckgo.com/?q=%243.43%20%2434.45&format=json
if (defined $tmp_result && $tmp_result ne 'inf' && $tmp_result =~ /^(?:\-|)[0-9\.]+$/) {
# Precisian.
my $precisian = 0;
# 0-9 check for http://yegg.duckduckgo.com/?q=%243.43%20%2434.45&format=json
if (defined $tmp_result && $tmp_result ne 'inf' && $tmp_result =~ /^(?:\-|)[0-9\.]+$/) {
# Precisian.
my $precisian = 0;
# too clever -- .5 ^ 2 not working right.
if (0) {
while ($query =~ /\.(\d+)/g) {
my $decimal = length($1);
$precisian = $decimal if $decimal > $precisian;
}
$tmp_result = sprintf( '%0.' . $precisian . 'f', $tmp_result ) if $precisian;
# too clever -- .5 ^ 2 not working right.
if (0) {
while ($query =~ /\.(\d+)/g) {
my $decimal = length($1);
$precisian = $decimal if $decimal > $precisian;
}
# Dollars.
if ($query =~ /^\$/) {
$tmp_result = qq(\$$tmp_result);
}
# Query for display.
my $tmp_q = $query;
# Drop equals.
$tmp_q =~ s/\=$//;
$tmp_q =~ s/((?:\d+?|\s))E(-?\d+)/\($1 * 10^$2\)/;
# Copy
$results_no_html = $results_html = $tmp_q;
# Superscript (before spacing).
$results_html =~ s/\^([^\)]+)/<sup>$1<\/sup>/g;
$results_html =~ s/\^(\d+|\b(?:e|c|dozen|gross|pi)\b)/<sup>$1<\/sup>/g;
($results_no_html, $results_html) = (spacing($results_no_html), spacing($results_html));
return if $results_no_html =~ /^\s/;
# Add commas.
$tmp_result = commify($tmp_result);
# Now add it back.
$results_no_html .= ' = ';
$results_html .= ' = ';
$results_html = qq(<div>$results_html<a href="javascript:;" onClick="document.x.q.value='$tmp_result';document.x.q.focus();">$tmp_result</a></div>);
return $results_no_html . $tmp_result, html => $results_html, heading => "Calculator";
$tmp_result = sprintf( '%0.' . $precisian . 'f', $tmp_result ) if $precisian;
}
# Dollars.
if ($query =~ /^\$/) {
$tmp_result = qq(\$$tmp_result);
}
# Query for display.
my $tmp_q = $query;
# Drop equals.
$tmp_q =~ s/\=$//;
$tmp_q =~ s/((?:\d+?|\s))E(-?\d+)/\($1 * 10^$2\)/;
# Copy
$results_no_html = $results_html = $tmp_q;
# Superscript (before spacing).
$results_html =~ s/\^([^\)]+)/<sup>$1<\/sup>/g;
$results_html =~ s/\^(\d+|\b(?:e|c|dozen|gross|pi)\b)/<sup>$1<\/sup>/g;
($results_no_html, $results_html) = (spacing($results_no_html), spacing($results_html));
return if $results_no_html =~ /^\s/;
# Add commas.
$tmp_result = commify($tmp_result);
# Now add it back.
$results_no_html .= ' = ';
$results_html .= ' = ';
$results_html = qq(<div>$results_html<a href="javascript:;" onClick="document.x.q.value='$tmp_result';document.x.q.focus();">$tmp_result</a></div>);
return $results_no_html . $tmp_result, html => $results_html, heading => "Calculator";
}
}