mirror of
https://github.com/Z3Prover/z3
synced 2025-08-03 01:40:22 +00:00
Z3 sources
Signed-off-by: Leonardo de Moura <leonardo@microsoft.com>
This commit is contained in:
parent
3f9edad676
commit
e9eab22e5c
1186 changed files with 381859 additions and 0 deletions
61
lib/approx_nat.cpp
Normal file
61
lib/approx_nat.cpp
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*++
|
||||
Copyright (c) 2007 Microsoft Corporation
|
||||
|
||||
Module Name:
|
||||
|
||||
approx_nat.cpp
|
||||
|
||||
Abstract:
|
||||
|
||||
Approximated natural numbers. It performs operations on the set [0, ..., 2^{n-2}, huge].
|
||||
Where huge represents all numbers greater than 2^{n-2}.
|
||||
|
||||
Author:
|
||||
|
||||
Leonardo (leonardo) 2008-01-11
|
||||
|
||||
Notes:
|
||||
|
||||
--*/
|
||||
#include"approx_nat.h"
|
||||
|
||||
approx_nat::approx_nat(unsigned val) {
|
||||
m_value = val > m_limit ? UINT_MAX : val;
|
||||
}
|
||||
|
||||
approx_nat & approx_nat::operator=(unsigned val) {
|
||||
m_value = val > m_limit ? UINT_MAX : val;
|
||||
return *this;
|
||||
}
|
||||
|
||||
approx_nat & approx_nat::operator+=(unsigned w) {
|
||||
if (is_huge())
|
||||
return *this;
|
||||
if (w > m_limit) {
|
||||
m_value = UINT_MAX;
|
||||
return *this;
|
||||
}
|
||||
m_value += w;
|
||||
if (m_value > m_limit)
|
||||
m_value = UINT_MAX;
|
||||
return *this;
|
||||
}
|
||||
|
||||
approx_nat & approx_nat::operator*=(unsigned w) {
|
||||
if (is_huge())
|
||||
return *this;
|
||||
unsigned long long r = static_cast<unsigned long long>(m_value) * static_cast<unsigned long long>(w);
|
||||
if (r > m_limit)
|
||||
m_value = UINT_MAX;
|
||||
else
|
||||
m_value = static_cast<unsigned>(r);
|
||||
return *this;
|
||||
}
|
||||
|
||||
std::ostream & operator<<(std::ostream & target, approx_nat const & w) {
|
||||
if (w.is_huge())
|
||||
target << "[huge]";
|
||||
else
|
||||
target << w.get_value();
|
||||
return target;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue