Skip to content

Commit 1023846

Browse files
committed
Use numeric_cast_v<unsigned> instead of deprecated integer2unsigned
1 parent 26d0b0a commit 1023846

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/util/arith_tools.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ bool to_unsigned_integer(const constant_exprt &expr, unsigned &uint_value)
100100
return true;
101101
else
102102
{
103-
uint_value=integer2unsigned(i);
103+
uint_value = numeric_cast_v<unsigned>(i);
104104
return false;
105105
}
106106
}
@@ -240,7 +240,7 @@ mp_integer power(const mp_integer &base,
240240
case 2:
241241
{
242242
mp_integer result;
243-
result.setPower2(exponent.to_ulong());
243+
result.setPower2(numeric_cast_v<unsigned>(exponent));
244244
return result;
245245
}
246246
case 1: return 1;

src/util/config.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1106,7 +1106,7 @@ static unsigned unsigned_from_ns(
11061106
throw
11071107
"failed to convert symbol table configuration entry `"+id2string(id)+"'";
11081108

1109-
return integer2unsigned(int_value);
1109+
return numeric_cast_v<unsigned>(int_value);
11101110
}
11111111

11121112
void configt::set_from_symbol_table(

src/util/ieee_float.cpp

+10-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ Author: Daniel Kroening, [email protected]
88

99
#include "ieee_float.h"
1010

11-
#include <cstdint>
1211
#include <ostream>
1312
#include <cassert>
1413
#include <cmath>
@@ -1164,7 +1163,11 @@ bool ieee_floatt::is_float() const
11641163
/// for NaN.
11651164
double ieee_floatt::to_double() const
11661165
{
1167-
union { double f; uint64_t i; } a;
1166+
static_assert(
1167+
sizeof(unsigned long long) == sizeof(double),
1168+
"ieee_floatt::to_double not supported on this architecture");
1169+
1170+
union { double f; unsigned long long i; } a;
11681171

11691172
if(infinity_flag)
11701173
{
@@ -1193,12 +1196,11 @@ double ieee_floatt::to_double() const
11931196
/// for NaN.
11941197
float ieee_floatt::to_float() const
11951198
{
1196-
if(sizeof(unsigned)!=sizeof(float))
1197-
{
1198-
throw "ieee_floatt::to_float not supported on this architecture";
1199-
}
1199+
static_assert(
1200+
sizeof(unsigned) == sizeof(float),
1201+
"ieee_floatt::to_float not supported on this architecture");
12001202

1201-
union { float f; uint32_t i; } a;
1203+
union { float f; unsigned i; } a;
12021204

12031205
if(infinity_flag)
12041206
{
@@ -1219,7 +1221,7 @@ float ieee_floatt::to_float() const
12191221
mp_integer i=pack();
12201222
assert(i.is_ulong());
12211223

1222-
a.i=i.to_ulong();
1224+
a.i = numeric_cast_v<unsigned>(i);
12231225
return a.f;
12241226
}
12251227

0 commit comments

Comments
 (0)