Same conversion but without any lookup
This commit is contained in:
parent
e3140a3add
commit
a68815b3cd
2 changed files with 3 additions and 11 deletions
|
@ -159,14 +159,6 @@ namespace dhandy {
|
|||
using RetType = RevArray<I, 10, Tr>;
|
||||
using Num = implem::NumberAdaptation<I, 10>;
|
||||
|
||||
//How to build this lookup: 1) write numbers 0, 10, 20..., 90
|
||||
//in binary; 2) take the lowest 5 bits, div by 2 and write as
|
||||
//decimal; 3) divide by 2; 4) the result is the position in the
|
||||
//below array that should be filled in with the leading digit
|
||||
//from the original 0-90 number
|
||||
constexpr const char lookup[16] = {
|
||||
0, 0, 0, 7, 4, 1, 0, 0, 8, 5, 2, 0, 0, 9, 6, 3
|
||||
};
|
||||
const bool was_negative = implem::is_negative<I, 10>(in);
|
||||
|
||||
RetType arr;
|
||||
|
@ -178,7 +170,7 @@ namespace dhandy {
|
|||
const auto last_two = in % 100;
|
||||
const auto digit_low = in % 10;
|
||||
in = static_cast<I>(in / static_cast<I>(100));
|
||||
const auto digit_high = lookup[((last_two - digit_low) >> 1) & 0xF];
|
||||
const auto digit_high = last_two / 10;
|
||||
arr.push_front(Tr::to_digit(static_cast<int>(digit_low)));
|
||||
arr.push_front(Tr::to_digit(static_cast<int>(digit_high)));
|
||||
};
|
||||
|
@ -187,7 +179,7 @@ namespace dhandy {
|
|||
}
|
||||
else {
|
||||
const auto digit_low = in % 10;
|
||||
const auto digit_high = lookup[((in - digit_low) >> 1) & 0xF];
|
||||
const auto digit_high = (in / 10) % 10;
|
||||
arr.push_front(Tr::to_digit(static_cast<int>(digit_low)));
|
||||
arr.push_front(Tr::to_digit(static_cast<int>(digit_high)));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ void run_with_timing (
|
|||
|
||||
int main() {
|
||||
using dhandy::int_conv;
|
||||
constexpr const std::size_t count = 50'000'000;
|
||||
constexpr const std::size_t count = 70'000'000;
|
||||
|
||||
std::vector<unsigned int> nums;
|
||||
std::vector<std::string> strings;
|
||||
|
|
Loading…
Reference in a new issue