Skip to content

Commit 3bfe437

Browse files
committed
Fix bigint integer cast
1 parent 46067a8 commit 3bfe437

File tree

1 file changed

+5
-16
lines changed

1 file changed

+5
-16
lines changed

include/jsoncons/utility/bigint.hpp

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,28 +1199,17 @@ class basic_bigint
11991199
return get_storage_view().size() != 0 ? true : false;
12001200
}
12011201

1202-
explicit operator int64_t() const
1202+
template <typename Integer, typename = typename std::enable_if<std::is_integral<Integer>::value && sizeof(Integer) <= sizeof(int64_t)>::type>
1203+
explicit operator Integer() const
12031204
{
12041205
auto this_view = get_storage_view();
1205-
int64_t x = 0;
1206+
Integer x = 0;
12061207
if (this_view.size() > 0)
12071208
{
1208-
x = static_cast<int64_t>(this_view[0]);
1209+
x = static_cast<Integer>(this_view[0]);
12091210
}
12101211

1211-
return is_negative() ? -x : x;
1212-
}
1213-
1214-
explicit operator word_type() const
1215-
{
1216-
auto this_view = get_storage_view();
1217-
word_type u = 0;
1218-
if ( this_view.size() > 0 )
1219-
{
1220-
u = this_view[0];
1221-
}
1222-
1223-
return u;
1212+
return is_negative() ? x*(-1) : x;
12241213
}
12251214

12261215
explicit operator double() const

0 commit comments

Comments
 (0)