Merge pull request #585 from mwmiller/bangalator
Calculator: fix bangful query result. Ping @jagtalonmaster
commit
3eb97e456e
|
@ -26,7 +26,7 @@ attribution
|
|||
|
||||
triggers query_nowhitespace => qr<
|
||||
^
|
||||
( what is | calculate | solve | math )? !?
|
||||
( what is | calculate | solve | math )?
|
||||
|
||||
[\( \) x X * % + / \^ \$ -]*
|
||||
|
||||
|
@ -85,7 +85,6 @@ handle query_nowhitespace => sub {
|
|||
$query =~ s/^(?:whatis|calculate|solve|math)//;
|
||||
|
||||
if ($query !~ /[xX]\s*[\*\%\+\-\/\^]/ && $query !~ /^-?[\d]{2,3}\.\d+,\s?-?[\d]{2,3}\.\d+$/) {
|
||||
my $tmp_result = '';
|
||||
|
||||
# Grab expression.
|
||||
my $tmp_expr = spacing($query, 1);
|
||||
|
@ -114,6 +113,7 @@ handle query_nowhitespace => sub {
|
|||
# Using functions makes us want answers with more precision than our inputs indicate.
|
||||
my $precision = ($query =~ $funcy) ? undef : max(map { $style->precision_of($_) } @numbers);
|
||||
|
||||
my $tmp_result;
|
||||
eval {
|
||||
# e.g. sin(100000)/100000 completely makes this go haywire.
|
||||
alarm(1);
|
||||
|
@ -122,7 +122,7 @@ handle query_nowhitespace => sub {
|
|||
};
|
||||
|
||||
# Guard against non-result results
|
||||
return unless (defined $tmp_result && $tmp_result ne 'inf');
|
||||
return unless (defined $tmp_result && $tmp_result ne 'inf' && $tmp_result ne '');
|
||||
# Try to determine if the result is supposed to be 0, but isn't because of FP issues.
|
||||
# If there's a defined precision, let sprintf worry about it.
|
||||
# Otherwise, we'll say that smaller than 1e-7 was supposed to be zero.
|
||||
|
|
|
@ -324,7 +324,8 @@ ddg_goodie_test(
|
|||
'(pi^4.1^(5-4)+pi^(5-(4^2 -8)))^(1/6)+1' => test_zci(
|
||||
'(pi ^ 4.1 ^ (5 - 4) + pi ^ (5 - (4 ^ 2 - 8))) ^ (1 / 6) + 1 = 3.18645452799383',
|
||||
heading => 'Calculator',
|
||||
html => qr#\(pi<sup>4.1<sup>\(5 - 4\)</sup></sup> \+ pi<sup>\(5 - \(4<sup>2</sup> - 8\)\)</sup>\)<sup>\(1 / 6\)</sup> \+ 1<span class='text--secondary'> =#,
|
||||
html =>
|
||||
qr#\(pi<sup>4.1<sup>\(5 - 4\)</sup></sup> \+ pi<sup>\(5 - \(4<sup>2</sup> - 8\)\)</sup>\)<sup>\(1 / 6\)</sup> \+ 1<span class='text--secondary'> =#,
|
||||
),
|
||||
'5^4^(3-2)^1' => test_zci(
|
||||
'5 ^ 4 ^ (3 - 2) ^ 1 = 625',
|
||||
|
@ -382,6 +383,7 @@ ddg_goodie_test(
|
|||
dividedbydividedby => undef,
|
||||
time => undef, # We eval perl directly, only do whitelisted stuff!
|
||||
'four squared' => undef,
|
||||
'! + 1' => undef, # Regression test for bad query trigger.
|
||||
);
|
||||
|
||||
done_testing;
|
||||
|
|
Loading…
Reference in New Issue