Skip to content

Commit 8608963

Browse files
authored
Fix long_uint/long_int support
1. Implement make_unsigned type modifier 2. Add is_long_int_v trait class 3. Fix mulc method result if long_uint type used
1 parent 2766944 commit 8608963

1 file changed

Lines changed: 29 additions & 2 deletions

File tree

include/long_math.h

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
//
3131
////////////////////////////////////////////////////////////////////////////////////////////////////
3232
//
33-
// $Id:$
33+
// $Id: long_math.h 145 2021-09-04 11:21:08Z ykalmykov $
3434
//
3535
////////////////////////////////////////////////////////////////////////////////////////////////////
3636

@@ -86,6 +86,19 @@ inline constexpr bool is_signed_v = std::is_signed_v<type_t>;
8686

8787

8888

89+
////////////////////////////////////////////////////////////////////////////////////////////////////
90+
// make_unsigned_t
91+
////////////////////////////////////////////////////////////////////////////////////////////////////
92+
93+
template<typename type_t>
94+
struct make_unsigned {
95+
using type = typename std::make_unsigned<type_t>::type;
96+
};
97+
template<typename type_t>
98+
using make_unsigned_t = typename make_unsigned<type_t>::type;
99+
100+
101+
89102
////////////////////////////////////////////////////////////////////////////////////////////////////
90103
// is_long_uint_v
91104
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -99,6 +112,20 @@ inline constexpr bool is_long_uint_v<const long_uint_t<type_t, size>> = true;
99112

100113

101114

115+
116+
////////////////////////////////////////////////////////////////////////////////////////////////////
117+
// is_long_int_v
118+
////////////////////////////////////////////////////////////////////////////////////////////////////
119+
120+
template<typename>
121+
inline constexpr bool is_long_int_v = false;
122+
template<typename type_t, uint_t size>
123+
inline constexpr bool is_long_int_v<long_int_t<type_t, size>> = true;
124+
template<typename type_t, uint_t size>
125+
inline constexpr bool is_long_int_v<const long_int_t<type_t, size>> = true;
126+
127+
128+
102129
////////////////////////////////////////////////////////////////////////////////////////////////////
103130
// half
104131
////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -469,7 +496,7 @@ constexpr type_t mulc_classic(const type_t& value1, const type_t& value2, type_t
469496

470497
bool add_carry = false;
471498
result_lo = addc(result_lo, carry, add_carry);
472-
carry = addc(result_hi, type_t(), add_carry);
499+
carry = addc(result_hi, type_t(0), add_carry);
473500

474501
return result_lo;
475502
}

0 commit comments

Comments
 (0)