Commit Graph

87 Commits (db131264090b7c41c53ca993c553437808695fe5)

Author SHA1 Message Date
PJ Hampton 72729b7c16 Calculator: (URGENT) Fix math.js log|ln simplify issue. (#4183)
* Fix math.js simplify issue.

* Remove debug statements.

* Adds fact to the mix.

* Stash

* Fix greedy quantifier in trig and log/ln

* Don't trigger on anything with stuff after =

* allow triggering on <func> <number>

* Both sides of =

* Fix expressions.

* Tighten up triggering based on valid expressions.

* Remove dumper obj

* Tighten up word triggering.

* Allow only one currency through.

* Kill off symbols in js if allowed through.

* Allow negative numbers.

* Add support for negated numbers.

* Fix initialize issue.

* Refactor code slightly

* Tightened regexs

* Require space between log and input
2017-05-24 17:44:13 -04:00
PJ Hampton 137f98c31b Calculator: Add square root support from search bar. (#4182) 2017-05-09 16:53:43 -04:00
Zaahir Moolla f1142a6b21 tighten calculator regex, update tests (#4128) 2017-04-25 10:43:32 +01:00
PJ Hampton 3ea2787742 Added PercentOf logic to calculator. (#4122) 2017-04-24 12:59:03 -04:00
PJ Hampton 2e6590e29f Calculator: [Phase 4] Deprecate Perl Backend (#4110)
* Begin deprecating perl backend.

* Deprecate backend [skip ci]

* Routine checkin of code.

* Added docs + preprocessing.

* Deprecate perl eval backend.

* Checking in some code.'

* Handle bad search expressions by defaulting to 0

* Add ability to recover with grace from bad expressions from search bar.

* Removed unnessesary perl code.

* Add support for factorials with !

* cleanup trailing spaces

* Removed trig constants.

* Support tau in expression.

* Removed ln preprocess.

* Support leading =. Removed moot code.

* Add support for euro and pound.

* Removed nat lang query parsing from js.

* strip duplicate operators

* Fixed legacy spacing issue in tests.

* Remove empty exponent.

* Bail on hex looking entries.

* better handling of repeated operators

* Remove max import

* revert back to old check for 3+ operators

* relax phone number regex for now

* remove silly test
2017-04-21 13:12:41 -04:00
PJ Hampton 0abd6a6554 Calculator: [Phase 2] Add Scientific calculator (#4067)
* Phase 1: Add basic calculator

* Updated tests.

* change template name, use base template, prefill calc with answer

* fix test

* Added backlog features.

* Updated js.

* Light refactoring work

* Refactored keycodes.

* Updated C button.

* Rewrote (+/-)% Expressions

* Updated the spacing dertermination

* Added expression to UI by default.

* Update tests.

* Updated formatting.

* Rewrite percent queries.

* Pushing updated codebase.

* Add calculator as trigger word

* Update tests for new triggers

* Stop initializing expression if 0

* add precision support to math eval object.

* Removed scientific buttons / history for Phase 1

* Updated math type.

* Prevents duplicate OPERADNS

* Add duplicate functionality.

* Updated unicode.

* Removed es6 feature.

* Stop first entry being an operand.

* Add operator flipping.

* Added Precision support.

* Handle numpad operator keys

* Set and maintain focus, Improved event handling

* Bind click handler in loop, stopPropgation of keydown

* Cleanup trailing spaces

* Fixed broken assignment.

* Prevent multiple commas.

* Fixed calculator stalling when trying to enter a new operator

* Initial refactor.

* Refactored out expression array.

* Refactored out display var.

* reintroduced matheval object for precision.

* Cleaned up formatting.

* Removed commify.

* Initial PR for Phase 2

* Add support for brackets.

* Added support for Pi

* Add support for sin, tan, cos

* Added factorial support

* Add support for squared / cubed functions

* Add support for natural log

* Support log_10 function.

* Add support for square roots.

* Add eulers number.

* Implement Engineers Exponent / Formatted Funcs.

* Add sci-tab id to handlebars.

* Removed positioning for mobile display.

* Custom exponents 🚀

* Implemented Euler exponent

* Support 1/x button.

* Interactified deg/rad toggle.

* Add support for degrees / radians

* Fix radians bug.

* Zaahirs / Mintsofts syntactic changes.

* Fixed regex for exponents

* Removed blue from toggle.

* Allow backspacing through functions.

* Allow backspacing through exponents.

* Fix +99% bug.

* Allow flipping of keypads.

* Stop ! being entered first.

* Stop EE being entered at start or multiple.

* Allow step back through EE

* Disallow multiple periods. [skip ci]

* Rewrote query to handle natural language.

* Addressed phase 1 feedback.

* Fixed backspace bug.

* Allow backspacing through constants.

* Add auto paren support for funcs.

* Started the commenting 💥

* Add some comments.

* Updated PercentNormalizer comment.

* Fix 0/0 Error.

* Add 'c' key support

* Fix back spacing.

* Positioned deg / rad toggle.

* Refactoring code. Stage 1.

* Added high signal.

* Add funcs for Initite/NaN

* Moved eval info into separate function.

* Abstracted clear function.

* Add paren manager.

* Refactored out paren state.

* Refactored out parenState global

* Removed meta.

* Backspace through functions.

* Set signal to high.

* Fixed signal

* Pushing updated code.

* Refactored backspacing.

* Fix up messy code / document.

* Fixed + percent bug.

* Support EE on mobile.

* opens pseudo paren for 1/(x)

* Fix large factorial issue.

* Allow pi | e as exponent.

* use exponents on π and e.

* Removed +-3 issue.

* Natural log and log now work as exponents

* nit: cleaned up expression.

* Fixed percent error.

* Add phase 3 ledger span (hidden)

* Disabled add digits.

* Check in UX fixes.

* Some light refactoring.

* Swap functions.

* Fixed shoddy regex.

* Add ledger object for phase 3.

* Updated percentage / trig regex

* Add blank expression if error.

* Allow factorial on decimals.

* Update code + comments.

* Add in calc trigger word. Fixed Backspace.

* All backspacing fixed.

* Try to recover from open/unfinished exponent

* Add high signal for

* Update comments.

* Updated comments.

* improve calculator regex

* Strip trailing spaces`

* Updated signal code.

* Fixed backspacing issue.

* swap id for class (ParenManger)

* Remove console logs.

* Update comment.

* Fix bug in regex replacement.

* Calculator: [Phase 3] Add History / Calc reloading (#4081)

* Set up UI.

* Phase 3 implemented.

* Remove array. Replace with handlebars.

* strip commas by default.

* Fixed html interpolation

* Add g flag to replacement regex

* Strip trailing spaces

* remove unneeded option from perl

* Added comments to backspace.

* Removed ledger properties. Updated using state.

* Addressed Zaahir's p2 feedback
2017-04-12 15:31:12 -04:00
PJ Hampton dc12d569c6 Calculator: [Phase 1] Add basic calculator (#4051)
* Phase 1: Add basic calculator

* Updated tests.

* change template name, use base template, prefill calc with answer

* fix test

* Added backlog features.

* Updated js.

* Light refactoring work

* Refactored keycodes.

* Updated C button.

* Rewrote (+/-)% Expressions

* Updated the spacing dertermination

* Added expression to UI by default.

* Update tests.

* Updated formatting.

* Rewrite percent queries.

* Pushing updated codebase.

* Add calculator as trigger word

* Update tests for new triggers

* Stop initializing expression if 0

* add precision support to math eval object.

* Removed scientific buttons / history for Phase 1

* Updated math type.

* Prevents duplicate OPERADNS

* Add duplicate functionality.

* Updated unicode.

* Removed es6 feature.

* Stop first entry being an operand.

* Add operator flipping.

* Added Precision support.

* Handle numpad operator keys

* Set and maintain focus, Improved event handling

* Bind click handler in loop, stopPropgation of keydown

* Cleanup trailing spaces

* Fixed broken assignment.

* Prevent multiple commas.

* Fixed calculator stalling when trying to enter a new operator

* Initial refactor.

* Refactored out expression array.

* Refactored out display var.

* reintroduced matheval object for precision.

* Cleaned up formatting.

* Removed commify.

* Removed positioning for mobile display.

* Don't set focus on Calc automatically when displayed

* Add touchstart support.

* Prevent zooming.

* ensure button text is not selectable

* Add right borders to calc, ensure same border colour

* Cleanup code style

* Only apply hover state css to desktop
2017-04-06 16:40:56 -04:00
Zaahir Moolla 5f7329fc67 Calculator: Switch to canonical structured answer (#3916)
* Switch Calculator to canoncial structured answer

* Add Goodie Template
2017-02-06 16:06:33 -05:00
Zaahir Moolla 0ad6eba28a Calculator: Prevent anything but allowed ops in the query (#3903)
* prevent anything but allowed ops in the query
no negative nums

* Uncomment neg catch and move after garbage is removed

* Add more tests

* The hex check can be simplified since the trigger isn't allowing most of it
Allow expressions like 1e9 to pass

* Allow = in query
decimal/negatives with e

* Remove debug

* add test for 1e9 query
2017-01-30 17:46:21 -05:00
Zaahir Moolla 3309758c1d Calculator: More fixes -- Trigger regex contained a bug (#3898)
* Restrict some other stuff

* Don't require digit

* Restrict multiple ops to two or less

* reject empty parens/multiple ops

* No @, or $ not followed by a number or .

* combine char class

* add more negative tests

* Add ops back, case-insensitive subs, require two ops again

* Case-insensitive on multiple ops too

* Allow leading negatives

* Move the leading neg sub

* Better regex for hex input

* update tests
2017-01-28 14:07:00 -05:00
Zaahir Moolla 9322e7b34c Calculator: Improve triggering and execution (#3894)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets

* Silence all of reval's warnings

* Add STRICT
2017-01-26 10:45:49 -05:00
Zaahir Moolla a8d92e3cb5 Revert "ignore reval's warnings" (#3893) 2017-01-25 18:19:31 -05:00
Zach Thompson 369c894439 ignore reval's warnings (#3892)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets

* Silence all of reval's warnings
2017-01-25 17:35:25 -05:00
Zaahir Moolla 840cdc99a1 Revert "calculator: trigger/safe" (#3890) 2017-01-25 15:00:10 -05:00
Zach Thompson 2113d41a79 calculator: trigger/safe (#3878)
* Update trigger
Use Safe for evaluation with the minimum functions
Removed unnecessary capturing, redundant function calls

* Add some tests

* Remove eval since we don't allow die
Add comment about debugging failed reval

* Add rv2gv from :base_orig to allow compat with Safe 2.35
Remove prtf since that was in :base_orig which was removed

* Remove unneeded opsets
2017-01-24 15:00:37 -05:00
Zaahir Moolla 06196e98b5 Revert "Calculator: Dumb down the trigger" (#3868) 2017-01-20 15:49:16 -05:00
Zach Thompson 8e5d7b46e8 Calculator: Dumb down the trigger (#3866)
* Dumb down the calculator regex

* No interpolation

* Add tests to ensure changes work
2017-01-18 13:23:49 -05:00
Ben Moon 83b9bbd6b7 Fix newline at end of file 2016-05-16 14:19:39 +01:00
Ben Moon 5f85cf4121 Update Goodies to use Test::Deep
* Ensure Test::Deep is imported.

* Replace '-ANY-' with ignore()

* Replace regexes with re(...)
2016-05-16 14:07:57 +01:00
Ben Moon 204de9cb2e Fix spacing around minus sign
Previous fix introduced a small bug with spacing: things like
`1 + e - 3` were being expanded to `1 + e-3`. This fixes the
expansion.
2015-12-09 15:47:10 +00:00
Ben Moon e4865eb3cb Improve test coverage 2015-12-08 20:16:18 +00:00
Ben Moon a6573a7b2c Fix issue #1694
Fixes issue with expressions such as `1 + 2e-7` treating `e` as
the mathematical constant rather than `* 10 ^`.
2015-12-08 19:17:52 +00:00
Mailkov c86c1b0665 Issue 1418 - Factorial: Move integration into Calculator.pm; Calculate factorial with Math::BigInt bfac() 2015-11-23 15:47:31 +00:00
codetheweb 600bc22061 Add common US formating examples 2015-10-14 20:40:47 +00:00
codetheweb affb687f15 Add more test coverage 2015-10-12 19:21:36 +00:00
codetheweb ab15e8cc4e Fix phone number regex 2015-10-09 15:32:22 +00:00
codetheweb 645e237cc1 Add more test coverage 2015-10-01 18:14:58 +00:00
codetheweb b3fd5bb893 Ignore phone numbers 2015-09-25 23:28:28 +00:00
Daniel Smith 960f007888 Calculator.t: Added use utf8 2015-07-20 13:08:55 +00:00
Daniel Smith f517b5b80f Added support and tests for several multiplication symbols and obelus (÷) 2015-07-09 15:47:02 +00:00
Rob Emery a0410b9c52 Merge branch 'master' into mintsoft/calc-you-later
Conflicts:
	lib/DDG/Goodie/Calculator.pm
2015-03-29 23:14:44 +01:00
Rob Emery 563cb2909c Calculator: Updating tests with accurate output 2015-03-29 23:07:12 +01:00
Rob Emery 04f698bb5c Calculator: Adding failing tests for 2pi; currently implicit multiplication isn't supported 2015-03-29 22:49:43 +01:00
Rob Emery 145684d96c Calculator: Adding failing test for https://github.com/duckduckgo/zeroclickinfo-goodies/issues/1026 2015-03-29 22:37:07 +01:00
Jay Kamat 0a2c16861b Added more tests 2015-03-23 15:47:10 +00:00
jgkamat a983ece55d Added sqrt to the goodie caclulator 2015-03-21 05:22:53 +00:00
Chris Wilson 2f11d6cc76 Update Binary IA to Uppercase. Fix All Test Cases for Uppercase Changes. 2015-01-09 19:46:54 +11:00
Pattarawat Chormai fc9f44cb88 Fix test 2014-12-14 11:02:36 +07:00
Matt Miller fe1729edf1 Calculator: add structured answer. 2014-11-15 21:35:39 +02:00
Matt Miller 39a9204689 Calculator: expand number availability.
This adds the ability for numbers to contian spaces or underscores.  It
also makes me recognize once more how brittle all of these
inter-relationships are.
2014-11-15 09:14:34 +02:00
Matt Miller 02adf60315 Calculator: better guard for no-ops.
The old gaurd was kinda whacky (and wrong) and inverted all the logic.
So we'll dump out early when we recognize that no operations will be
done.
2014-11-05 00:38:18 +02:00
Jag Talon 6b667ccede Merge pull request #586 from mwmiller/small_calc
Calculator: better display for very small floats.
2014-08-18 18:07:26 -04:00
Matt Miller aa150cf685 Calculator: better display for very small floats.
With the addition of the number styling role, we've improved the output
for very small floats.  We don't need to round them any longer, since
they produce comprehensible display values and don't break anything.
2014-08-14 08:54:33 -04:00
Matt Miller 4d28815513 Calculator: remove ! from trigger regex.
There appears to be no value in this beingincluded and it makes things
evaluate incorrectly, so we'll just remove it.
2014-08-12 15:00:05 -04:00
Rob Emery 93fc908a99 Merge branch 'master' into mintsoft/conversion_calcs 2014-08-01 23:37:02 +01:00
Rob Emery 17a15ebe1c Calculator: uses the correct classes 2014-07-30 19:43:54 +01:00
Matt Miller 65d6f76978 NumberStyle: tighten up check for exponentials.
Also, some adjustments to Calculator to allow its tests to pass.
Still clearly not properly factored, but at least everything "works"
for the moment.
2014-07-27 22:23:04 +08:00
Rob Emery eee3b51734 Merge remote-tracking branch mwmiller's 'style_role/style_role' into mintsoft/conversion_calcs
Conflicts:
	lib/DDG/Goodie/Calculator.pm
2014-07-26 22:52:49 +01:00
Matt Miller 239bdb9072 Calculator: ignore attempts at subnet notation.
This one is much harder to hit, because the dotted quads must have 3
digits in each of the last 3 positions and they tend to start zero-ing
the mask earlier, but might as well cover this better, too.

Thanks to @mintsoft for the heads-up.
2014-07-10 05:33:43 +08:00
Matt Miller 89b900c5b1 Calculator: ignore probable attempts at CIDR notation.
If we get a dotted quad, slash and a number in the range of 0-32, it
seems more likely this is talking about network addresses, than trying
to do a calculation.

I, personally, think it's unlikely we ever should be dealing with dotted
quads, but I want to leave in the possiblity of a pasted-in euro-style
value.

Fixes #541.
2014-07-10 05:05:04 +08:00