mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 01:47:36 +00:00
AK: Allow Checked += Checked, and other such operations
The overflow state from both Checkeds is OR'ed in the result.
This commit is contained in:
parent
6b7c96589b
commit
dc17e01c99
1 changed files with 29 additions and 1 deletions
30
AK/Checked.h
30
AK/Checked.h
|
@ -1,6 +1,6 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2011-2019 Apple Inc. All rights reserved.
|
* Copyright (C) 2011-2019 Apple Inc. All rights reserved.
|
||||||
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
|
* Copyright (c) 2020-2021, Andreas Kling <kling@serenityos.org>
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -186,24 +186,52 @@ public:
|
||||||
m_value /= other;
|
m_value /= other;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Checked& operator+=(const Checked& other)
|
||||||
|
{
|
||||||
|
m_overflow |= other.m_overflow;
|
||||||
|
add(other.value());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Checked& operator+=(T other)
|
constexpr Checked& operator+=(T other)
|
||||||
{
|
{
|
||||||
add(other);
|
add(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Checked& operator-=(const Checked& other)
|
||||||
|
{
|
||||||
|
m_overflow |= other.m_overflow;
|
||||||
|
sub(other.value());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Checked& operator-=(T other)
|
constexpr Checked& operator-=(T other)
|
||||||
{
|
{
|
||||||
sub(other);
|
sub(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Checked& operator*=(const Checked& other)
|
||||||
|
{
|
||||||
|
m_overflow |= other.m_overflow;
|
||||||
|
mul(other.value());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Checked& operator*=(T other)
|
constexpr Checked& operator*=(T other)
|
||||||
{
|
{
|
||||||
mul(other);
|
mul(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr Checked& operator/=(const Checked& other)
|
||||||
|
{
|
||||||
|
m_overflow |= other.m_overflow;
|
||||||
|
div(other.value());
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Checked& operator/=(T other)
|
constexpr Checked& operator/=(T other)
|
||||||
{
|
{
|
||||||
div(other);
|
div(other);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue