mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 03:07:36 +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:
parent
b2f0697afc
commit
4b2b0a4d0e
3 changed files with 25 additions and 6 deletions
|
@ -68,6 +68,21 @@ KeypadValue KeypadValue::operator-(void) const
|
|||
return { -m_value, m_decimal_places };
|
||||
}
|
||||
|
||||
KeypadValue KeypadValue::sqrt(void) const
|
||||
{
|
||||
return KeypadValue { AK::sqrt((double)(*this)) };
|
||||
}
|
||||
|
||||
KeypadValue KeypadValue::invert(void) const
|
||||
{
|
||||
return KeypadValue { 1.0 / (double)(*this) };
|
||||
}
|
||||
|
||||
KeypadValue KeypadValue::operator/(KeypadValue const& rhs)
|
||||
{
|
||||
return KeypadValue { (double)(*this) / (double)rhs };
|
||||
}
|
||||
|
||||
bool KeypadValue::operator<(KeypadValue const& rhs)
|
||||
{
|
||||
return operator_helper<bool>(*this, rhs, [](KeypadValue const&, KeypadValue const&, i64 less_decimal_places_equalized, i64 more_decimal_places_equalized, bool lhs_is_less) {
|
||||
|
@ -139,7 +154,7 @@ KeypadValue::KeypadValue(double d)
|
|||
m_value = negative ? (-m_value) : m_value;
|
||||
}
|
||||
|
||||
KeypadValue::operator double()
|
||||
KeypadValue::operator double() const
|
||||
{
|
||||
double res = (double)m_value / AK::pow(10.0, (double)m_decimal_places);
|
||||
return res;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue