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

Calculator: Make double construction and conversion private

At this point, the double conversions should really only be
implementation details of the KeypadValue class. Therefore,
the constructor-from double and conversion-operator-to
double of KeypadValue are made private. Instead, the
required functionality is provided by KeypadValue itself.
The internal implementation is still done using doubles.
However, this opens us up to the possibility of having
loss-free square root, inversion and division in the future.
This commit is contained in:
creator1creeper1 2021-12-19 22:13:18 +01:00 committed by Brian Gianforcaro
parent b2f0697afc
commit 4b2b0a4d0e
3 changed files with 25 additions and 6 deletions

View file

@ -38,7 +38,7 @@ KeypadValue Calculator::begin_operation(Operation operation, KeypadValue argumen
m_has_error = true;
return argument;
}
res = KeypadValue { AK::sqrt((double)argument) };
res = argument.sqrt();
clear_operation();
break;
case Operation::Inverse:
@ -46,7 +46,7 @@ KeypadValue Calculator::begin_operation(Operation operation, KeypadValue argumen
m_has_error = true;
return argument;
}
res = KeypadValue { 1.0 / (double)argument };
res = argument.invert();
clear_operation();
break;
case Operation::Percent:
@ -98,7 +98,7 @@ KeypadValue Calculator::finish_operation(KeypadValue argument)
m_has_error = true;
return argument;
}
res = KeypadValue { (double)m_saved_argument / (double)argument };
res = m_saved_argument / argument;
break;
case Operation::Sqrt: