1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 15:27:35 +00:00

Calculator: Use KeypadValue class instead of double

Calculator now uses the KeypadValue class instead of double in
its internal calculations. By not constantly converting to
double back-and-forth, we do not use precision simply by, for
example, negating a number. This fixes #7484.
This commit is contained in:
creator1creeper1 2021-08-01 13:08:53 +02:00 committed by Ali Mohammad Pur
parent 97d2a5799e
commit 8f552c9979
6 changed files with 43 additions and 57 deletions

View file

@ -7,6 +7,7 @@
*/
#include "CalculatorWidget.h"
#include "KeypadValue.h"
#include <Applications/Calculator/CalculatorGML.h>
#include <LibGUI/Button.h>
#include <LibGUI/Label.h>
@ -96,8 +97,8 @@ CalculatorWidget::CalculatorWidget()
m_equals_button = *find_descendant_of_type_named<GUI::Button>("equal_button");
m_equals_button->on_click = [this](auto) {
double argument = m_keypad.value();
double res = m_calculator.finish_operation(argument);
KeypadValue argument = m_keypad.value();
KeypadValue res = m_calculator.finish_operation(argument);
m_keypad.set_value(res);
update_display();
};
@ -110,8 +111,8 @@ CalculatorWidget::~CalculatorWidget()
void CalculatorWidget::add_operation_button(GUI::Button& button, Calculator::Operation operation)
{
button.on_click = [this, operation](auto) {
double argument = m_keypad.value();
double res = m_calculator.begin_operation(operation, argument);
KeypadValue argument = m_keypad.value();
KeypadValue res = m_calculator.begin_operation(operation, argument);
m_keypad.set_value(res);
update_display();
};
@ -130,7 +131,7 @@ String CalculatorWidget::get_entry()
return m_entry->text();
}
void CalculatorWidget::set_entry(double value)
void CalculatorWidget::set_entry(KeypadValue value)
{
m_keypad.set_value(value);
update_display();