Warning fix
This fixes ary_to_int() for negative values
This commit is contained in:
parent
a5705c5be0
commit
79ca881bc1
2 changed files with 13 additions and 8 deletions
|
@ -166,6 +166,13 @@ namespace dhandy {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
[[gnu::always_inline,gnu::pure]]
|
||||||
|
inline T negated_ifn (T n, bool negate) {
|
||||||
|
//return static_cast<int32_t>(((static_cast<unsigned int>(n) - (mask bitand 1)) xor mask) bitor ((mask bitand 1) << 31));
|
||||||
|
return (negate ? -n : n);
|
||||||
|
}
|
||||||
|
|
||||||
template <typename I, unsigned int Base, typename Tr>
|
template <typename I, unsigned int Base, typename Tr>
|
||||||
struct AryConversion {
|
struct AryConversion {
|
||||||
template <typename C>
|
template <typename C>
|
||||||
|
@ -183,7 +190,7 @@ namespace dhandy {
|
||||||
retval += Tr::from_digit(beg[i]) * factor;
|
retval += Tr::from_digit(beg[i]) * factor;
|
||||||
factor *= Base;
|
factor *= Base;
|
||||||
}
|
}
|
||||||
return retval;
|
return negated_ifn(retval, was_negative);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -204,13 +211,6 @@ namespace dhandy {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
[[gnu::always_inline,gnu::pure]]
|
|
||||||
inline T negated_ifn (T n, bool negate) {
|
|
||||||
//return static_cast<int32_t>(((static_cast<unsigned int>(n) - (mask bitand 1)) xor mask) bitor ((mask bitand 1) << 31));
|
|
||||||
return (negate ? -n : n);
|
|
||||||
}
|
|
||||||
|
|
||||||
template <typename T, typename C, unsigned int Base, typename Tr>
|
template <typename T, typename C, unsigned int Base, typename Tr>
|
||||||
[[gnu::pure]]
|
[[gnu::pure]]
|
||||||
T to_integer_sse (const C* s, std::size_t l) {
|
T to_integer_sse (const C* s, std::size_t l) {
|
||||||
|
|
|
@ -155,4 +155,9 @@ TEST_CASE ("Check char array to int conversions", "[i2s][int_conv]") {
|
||||||
AryConversionTestHelper<int32_t, 16>("7fffffff", 0x7fffffff);
|
AryConversionTestHelper<int32_t, 16>("7fffffff", 0x7fffffff);
|
||||||
AryConversionTestHelper<bool, 10>("1", true);
|
AryConversionTestHelper<bool, 10>("1", true);
|
||||||
AryConversionTestHelper<bool, 10>("0", false);
|
AryConversionTestHelper<bool, 10>("0", false);
|
||||||
|
|
||||||
|
AryConversionTestHelper<signed int, 10>("-1", -1);
|
||||||
|
AryConversionTestHelper<signed int, 10>("-50000", -50000);
|
||||||
|
AryConversionTestHelper<int64_t, 10>("-1", -1);
|
||||||
|
AryConversionTestHelper<int64_t, 10>("-510123123123", -510123123123);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue