From a0d967d13c95572886a8eb4d59de36e4250341f4 Mon Sep 17 00:00:00 2001 From: Brett Stime Date: Thu, 2 Feb 2017 09:47:43 -0600 Subject: [PATCH 1/4] Increases threshold before exponent notation My particular concern is: When I query: "bytes in 1 mib" I want a precise response: "1,048,576 bytes" ...instead of "1.05 * 10^6 bytes" Beyond that, generally, I believe that most people who can cognitively handle numbers up to 1MM can also handle any number with a seven digit integer-part/characteristic (http://math.stackexchange.com/a/64045/92444). Ideally, the decision should be made based on the number of characters in the significand (https://en.wikipedia.org/wiki/Significand) but that's beyond what I have time for at the moment (especially given how rusty my perl is) ;) . --- lib/DDG/Goodie/Conversions.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/Conversions.pm b/lib/DDG/Goodie/Conversions.pm index 46378c807..1e8bd1294 100755 --- a/lib/DDG/Goodie/Conversions.pm +++ b/lib/DDG/Goodie/Conversions.pm @@ -153,7 +153,7 @@ handle query_lc => sub { # We only display it in exponent form if it's above a certain number. # We also want to display numbers from 0 to 1 in exponent form. - if($result->{'result'} > 1_000_000 || abs($result->{'result'}) < 1) { + if($result->{'result'} > 9_999_999 || abs($result->{'result'}) < 1) { $formatted_result = (sprintf "%.${precision}g", $result->{'result'}); } } From cbeb0a8beb92b24b66f0eb68c1ab6328ab93096c Mon Sep 17 00:00:00 2001 From: Brett Stime Date: Thu, 2 Feb 2017 16:35:25 -0600 Subject: [PATCH 2/4] Attempts to fix test after formatting change --- t/Conversions.t | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/t/Conversions.t b/t/Conversions.t index f3ab746cb..0346bf4eb 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -780,14 +780,14 @@ ddg_goodie_test( physical_quantity => 'power' }) ), - '1 gigawatt in horsepower' => test_zci( - '1 gigawatt = 1.34 * 10^6 horsepower', + '10 gigawatt in horsepower' => test_zci( + '10 gigawatt = 1.34 * 10^7 horsepower', structured_answer => make_answer({ - markup_input => '1', - raw_input => '1', + markup_input => '10', + raw_input => '10', from_unit => 'gigawatt', - styled_output => '1.34 * 106', - raw_answer => '1.34*10^6', + styled_output => '1.34 * 107', + raw_answer => '1.34*10^7', to_unit => 'horsepower', physical_quantity => 'power' }) @@ -2774,8 +2774,8 @@ ddg_goodie_test( markup_input => '3,000', raw_input => '3000', from_unit => 'kilometers', - styled_output => '3 * 106', - raw_answer => '3*10^6', + styled_output => '3,000,000', + raw_answer => '3000000', to_unit => 'meters', physical_quantity => 'length' }) @@ -2804,6 +2804,18 @@ ddg_goodie_test( physical_quantity => 'length' }) ), + 'how many bytes in a mebibyte?' => test_zci( + '1 mebibyte = 1,048,576 megabytes', + structured_answer => make_answer({ + markup_input => '1', + raw_input => '1', + from_unit => 'mebibyte', + styled_output => '1,048,576', + raw_answer => '1048576', + to_unit => 'bytes', + physical_quantity => 'digital' + }) + ), 'how many megabytes in a gigabyte?' => test_zci( '1 gigabyte = 1,000 megabytes', structured_answer => make_answer({ From 7bbf1f41c8491315eb7d6ec14d7f58bd82e97631 Mon Sep 17 00:00:00 2001 From: Brett Stime Date: Thu, 2 Feb 2017 17:03:21 -0600 Subject: [PATCH 3/4] Attempts fix again --- t/Conversions.t | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/Conversions.t b/t/Conversions.t index 0346bf4eb..da742cc5c 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -2769,7 +2769,7 @@ ddg_goodie_test( }) ), '3000 km to m' => test_zci( - '3,000 kilometers = 3 * 10^6 meters', + '3,000 kilometers = 3,000,000 meters', structured_answer => make_answer({ markup_input => '3,000', raw_input => '3000', @@ -2805,7 +2805,7 @@ ddg_goodie_test( }) ), 'how many bytes in a mebibyte?' => test_zci( - '1 mebibyte = 1,048,576 megabytes', + '1 mebibyte = 1,048,576 bytes', structured_answer => make_answer({ markup_input => '1', raw_input => '1', From eb380de459190b673a6563283f1cdbdc65d79988 Mon Sep 17 00:00:00 2001 From: Brett Stime Date: Thu, 2 Feb 2017 17:08:24 -0600 Subject: [PATCH 4/4] Attempts fix test again --- t/Conversions.t | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/Conversions.t b/t/Conversions.t index da742cc5c..bb7bb584a 100755 --- a/t/Conversions.t +++ b/t/Conversions.t @@ -780,12 +780,12 @@ ddg_goodie_test( physical_quantity => 'power' }) ), - '10 gigawatt in horsepower' => test_zci( - '10 gigawatt = 1.34 * 10^7 horsepower', + '10 gigawatts in horsepower' => test_zci( + '10 gigawatts = 1.34 * 10^7 horsepower', structured_answer => make_answer({ markup_input => '10', raw_input => '10', - from_unit => 'gigawatt', + from_unit => 'gigawatts', styled_output => '1.34 * 107', raw_answer => '1.34*10^7', to_unit => 'horsepower',