Skip to content

Commit 13a058c

Browse files
committed
De-duplicate logic for bitvector max/min values
We should only store these arithmetic calculations in one place in the codebase.
1 parent 35a0ac3 commit 13a058c

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/util/std_types.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Author: Daniel Kroening, [email protected]
1313
#include "std_types.h"
1414

1515
#include "arith_tools.h"
16+
#include "bv_arithmetic.h"
1617
#include "namespace.h"
1718
#include "std_expr.h"
1819
#include "string2int.h"
@@ -163,12 +164,12 @@ mp_integer range_typet::get_to() const
163164

164165
mp_integer signedbv_typet::smallest() const
165166
{
166-
return -power(2, get_width()-1);
167+
return bv_spect(*this).min_value();
167168
}
168169

169170
mp_integer signedbv_typet::largest() const
170171
{
171-
return power(2, get_width()-1)-1;
172+
return bv_spect(*this).max_value();
172173
}
173174

174175
constant_exprt signedbv_typet::zero_expr() const
@@ -188,12 +189,12 @@ constant_exprt signedbv_typet::largest_expr() const
188189

189190
mp_integer unsignedbv_typet::smallest() const
190191
{
191-
return 0;
192+
return bv_spect(*this).min_value();
192193
}
193194

194195
mp_integer unsignedbv_typet::largest() const
195196
{
196-
return power(2, get_width())-1;
197+
return bv_spect(*this).max_value();
197198
}
198199

199200
constant_exprt unsignedbv_typet::zero_expr() const

0 commit comments

Comments
 (0)