|
@@ -12,6 +12,12 @@
|
|
|
|
|
|
Optional<Crypto::BigFraction> Calculator::operation_with_literal_argument(Operation operation, Crypto::BigFraction argument)
|
|
|
{
|
|
|
+ // Support binary operations with percentages, for example "2+3%" == 2.06
|
|
|
+ if (m_binary_operation_in_progress != Operation::None && operation == Operation::Percent) {
|
|
|
+ argument = m_binary_operation_saved_left_side * Crypto::BigFraction { 1, 100 } * argument;
|
|
|
+ operation = Operation::None; // Don't apply the "%" operation twice
|
|
|
+ }
|
|
|
+
|
|
|
// If a previous operation is still in progress, finish it
|
|
|
// Makes hitting "1+2+3=" equivalent to hitting "1+2=+3="
|
|
|
if (m_binary_operation_in_progress != Operation::None) {
|
|
@@ -20,7 +26,8 @@ Optional<Crypto::BigFraction> Calculator::operation_with_literal_argument(Operat
|
|
|
|
|
|
switch (operation) {
|
|
|
case Operation::None:
|
|
|
- VERIFY_NOT_REACHED();
|
|
|
+ m_current_value = argument;
|
|
|
+ break;
|
|
|
|
|
|
case Operation::Add:
|
|
|
case Operation::Subtract:
|