summaryrefslogtreecommitdiffstats
path: root/src/com/android/calculator2/Evaluator.java
Commit message (Collapse)AuthorAgeFilesLines
* Improve copy/paste handling, minor instant result fixesHans Boehm2015-05-131-0/+1
| | | | | | | | | | | | | | | | | | | | | | Bug: 20764417 Bug: 20838790 Finish the action mode when we do almost anything else. We should probably be even more aggressive about terminating it, and we may eventually want to use a different approach. But this avoids the crashes, and greatly improves the behavior. Display copy menu only when there is something to copy. Fix a couple of bugs introduced by recent instant display overhaul (one line each): - Instant display disappeared on rotation. - It was sometimes still possible to scroll the previous result after CLR. Change-Id: I1a91d312358898add1e281aaba116d709b4c92a7
* Fix CHAR_LIMIT for stringsJustin Klaassen2015-05-071-9/+10
| | | | | | | | | | | Bug: 20877857 Bug: 20815563 - Condensed strings to one string.xml with translatable="false". - Made functions and digits NOT localized. - Switched to U+2007 character for unknown digits. Change-Id: I51a108309ccfa9c40edd6f87f9e052ba7ee25e3a
* Fix paste bugHans Boehm2015-05-011-0/+1
| | | | | | | | Bug: 20764843 Pasting in a number changes the expression value. Duh. Change-Id: Ia4234632833767fd3d8614f56feec9dcf123ae3c
* Fix timeout, cancellation and instant display logicHans Boehm2015-05-011-57/+105
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bug: 20668802 Bug: 20484451 Bug: 20734909 Bug: 20738335 Change the timeout implementation to not rely on removing scheduled timeouts when an evaluation completes. This seems simper, more clearly correct and, unlike its predessessor seems to work reliably. Correctly display "cancelled" message, but only when cancelled for a reason other than timeout. Change SyntaxError to not be a Java "Error", since we routinely recover from it. Better support evaluation of partial expressions by removing trailing operators. Make some attempt to avoid redundant evaluations, since they're not as cheap as they used to be. Change the display logic to avoid frequent clearing of the display, which resulted in visible flashing. Note that the evaluation logic can now stop evaluating before the end of an expression. Substantially lengthen timeout used when computing an unrequested result. Inverse trig functions can be slow. See b/20729963. Make large factorial computations interruptable, as I mistakenly thought they were. Ignore "=" on an empty expression. I'm not positive this fixes the b/20484451, but I haven't been able to reproduce it with this patch. I have no idea whether it addresses b/20738335, but it cleans up code in that vicinity, so it would be interesting to know whether that is still reproducible. Change-Id: I67af5afc00e19a6156e1547ce4e2060c70ca367f
* Fix strings, stability bug, easy UI & correctness issuesHans Boehm2015-04-291-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Bug: 20625562 Bug: 20649711 Bug: 20561890 Bug: 20561528 Bug: 20442590 Bug: 15473140 Bug: 20503008 Bug: 20503007 - Improve timeout text. - Recalculate when Calculator is rotated, e.g. in error state, thus reproducing message. It's unclear this is good enough, but it's better. - Fix square root parsing. - Fix concatenation of numbers when pasting by adding explicit multiplication. - Display divide by zero error differently from other domain errors. - Improved advanced keypad layout of portrait-mode tablet calculator. - Improved overflow menu order. (More to be done.) - Report zero division as zero division when we can recognize it. - Switch to floating menus for copy/paste. Change-Id: I3875414f293e62a59b0e41f0de822f29bd5ac6a6
* Restructure display formatting, use TextView for formula.Hans Boehm2015-04-281-102/+44
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes issues with inappropriate keyboard popups and cleans up the code. This substantially rewrites the result formatting code; it intentionally removes a heuristic to avoid conventional scientific notation for short results, which only seemed to confuse things. There are some other tweaks and simplifications. Transitions to and from conventional scientific notation should be smoother, though there is still an issue with numbers like 10^-30. The formatting code is completely extracted from Evaluator, cutting off various tentacles, and moved to CalculatorResult. Fixes a bug that resulted in digits being inappropriately displayed without an exponent if the decimal point was just off the left edge of the screen. It's still not clear that we should always be integrating the exponent into the result window. Bug: 20483801 Bug: 20480081 Change-Id: I1bb777b871e9fa8b6cd510c533e4b94bde6d4a20
* Fix result overlap, clear logic, display bugs, etc.Hans Boehm2015-04-201-3/+10
| | | | | | | | | | | | | | | | | | | | | Adjust result padding to prevent overlapping with options menu, resulting in inability to access options menu. Reset state correctly after clear, preventing occasional crashes. Do this at end of animation to prevent animation glitches. Have clear but the display in a state in which COPY does nothing interesting. Treat a not-known-to-be-exact zero result better. Before this we displayed it as just "0", giving the mistaken impression of exactness. It is unclear whether we should display it as "0.00000000" or add an exponent to indicate the real evaluation precision. The former probably works better for beginners; the latter for experts. We now do the former, which is probably right. Also correctly save and restore not-yet analyzed characters. Change-Id: Iac46d0d3b5a06f61beb6af7d4f0910e43284f52b
* Internationalize display again. Plus minor cleanups.Hans Boehm2015-04-151-10/+15
| | | | | | | | | Adds code for internationalization of numeric results, both in the result and formula displays. Update some now obsolete TODO comments. Change-Id: I42731bf87f5488375457f1c5c094c7f0d17b71da
* Fix UI holes and bugs. Fix eval bugs.Hans Boehm2015-04-151-20/+101
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Change layout to make the result display use a fixed font size and limit the number of characters when it appears below the formula. This allows us to always get the proper expansion effect and prevents scrolling from affecting the font size. Add copy support for result display. Add paste support for the formula. Add keyboard input support. Copy/paste can be used to remember old results in the calculator. We save an identifying tag URI in the clip, in addition to text, allowing us to paste old calculator results without precision loss. Copy/paste currently does not rely on selection at all. I had trouble making it work that way in the formula. It's unclear that would be better, since we only allow copy of the entire text and paste at the end. Add a couple of alternate result display options to the overflow menu. (These appear quite useful, were trivial to implement, and give us a better excuse for the overflow menu.) Changed the behavior of the delete key in error state. Changing it to CLEAR seemed unfriendly, since it prevents corrections. This is a change from L. Made it clear that the CalculatorHitSomeButtons test is currently 95% worthless. It was apparentlly failing (due to test infrastructure issues) but throwing an exception in a thread from which it was not getting reported. Decided to keep it, since I would like a place to continue collecting regression tests, even if we can't actually run them yet. Includes some easy drive-by fixes for expression evaluation: a) 2 / 2 * 3 was mis-parsed as 2 / (2 * 3). b) Cosine evaluation had the sense of the test for a rational result reversed. c) Constants without leading digits, like .1, are now handled correctly, and decimal points in the formula are now internationalized. (That's not yet true for the result.) Change-Id: Ic24466b444b4a4633cfb036c67622c7f4fd644ec
* Add degree/radian mode, improve button layoutHans Boehm2015-04-081-4/+5
| | | | | | | | | | | | | Add a button for switching between degree and radian mode. Handle display updates in response to mode switching in a reasonoble way. Improve the button layout so that it is usable on tablets. Add DEG/RAD mode display at the top. Fiddle with some of the layout parameters so they make more sense to me. This may need further tuning. Change-Id: I8d04b235cfcb1f0a0d8f4a0ad6a0dc6e5eac8c5d
* Add BoundedRational evaluationHans Boehm2015-03-101-16/+34
| | | | | | | | | | | | | | | | | | | | | We would like to display finite representations of calculator results when they clearly exist and are easy to identify, such as when adding currency values. We do this by computing a rational representation of the result when it exists, and using that to compute the number of digits in a finite representation. Since rational arithmetic can become very expensive, we bound the size of the results we are willing to keep. If things get too large we fall back on the standard constructive real arithmetic. Finite representations are extremely unlikely in such cases anyway. This also gives us a clear rule for when to normalize fractions, which is often a challenge with rational number packages. This also adds a couple of routines to set degree mode, but does not include the UI to actually invoke them. Thus there is still no way to test some important pieces of functionality. Change-Id: I3c1aca5aefd8d8c19bce79095bde59ee3b4127fe
* Beginnings of ExactCalculator based on LHans Boehm2015-03-061-0/+768
Replace the arity library with a new evaluation engine based on an open source "constructive reals" library. This provides answers that are correct to the last displayed digit, and can be scrolled to get more precision, with evaluation to additional precision proceeding on demand. This uses pieces of an old prototype calculator with a pre-Material-Design UI. Since the code structure of the KitKat and Lollipop calculators is quite different, this merge required major changes to make the pieces fit again. An egregious bug in the prototype related to the evaluation of the power operator was fixed. Many new UI bugs are introduced to compensate :-) Add separate buttons for inverse trig functions. Add long TODO lists for various missing pieces. This is really designed to get something up and running that looks like it has a Material Design UI. This version kind of works, though with many UI deficiencies. This addresses external issues 63368, 81089, and 80990. It partially address the degree vs radian (80330) issue as well, though we're still missing the UI for that. This fixes Bug:15284587 (More work is needed to make this interact correctly with keyboard support.) Degree/Radian mode is also internal Bug:17059768 This provides much more robust solutions to the following, which were previously fixed by favoring round numbers over precise solutions: Bug:15747298 Bug:15332726 Change-Id: Ib64ffcee9760a3195ae2a48302308eeb09a156bd