Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exposing limb type choice by introducing _ZL and _ZLL #48

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion include/ctbignum/decimal_literals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,12 @@ constexpr auto chars_to_integer_seq(std::integer_sequence<char, Chars...>,
} //end of detail namespace

namespace literals {
template <char... Chars> constexpr auto operator"" _Z() {
template <char... Chars> [[deprecated("Consider using _ZL or _ZLL which explicitly specifies limb size as uint32_t or uint64_t")]] constexpr auto operator"" _Z() {

using T = uint64_t; // Question: How to elegantly expose the choice of this
// type to the user?
// Answer: Check below, inspired from `The type of the literal`
// table at https://en.cppreference.com/w/cpp/language/integer_literal

constexpr size_t len = sizeof...(Chars);
constexpr size_t N = 1 + (10 * len) / (3 * std::numeric_limits<T>::digits);
Expand All @@ -63,6 +65,30 @@ template <char... Chars> constexpr auto operator"" _Z() {
constexpr auto L = detail::tight_length(num) + (to_big_int(num) == big_int<1, T>{});
return detail::take_first(num, std::make_index_sequence<L>{});
}

template <char... Chars> constexpr auto operator"" _ZL() {

using T = uint32_t;

constexpr size_t len = sizeof...(Chars);
constexpr size_t N = 1 + (10 * len) / (3 * std::numeric_limits<T>::digits);

auto num = detail::chars_to_integer_seq<T>(std::integer_sequence<char, Chars...>{}, std::make_index_sequence<N>{});
constexpr auto L = detail::tight_length(num) + (to_big_int(num) == big_int<1, T>{});
return detail::take_first<T>(num, std::make_index_sequence<L>{});
}

template <char... Chars> constexpr auto operator"" _ZLL() {

using T = uint64_t;

constexpr size_t len = sizeof...(Chars);
constexpr size_t N = 1 + (10 * len) / (3 * std::numeric_limits<T>::digits);

auto num = detail::chars_to_integer_seq<T>(std::integer_sequence<char, Chars...>{}, std::make_index_sequence<N>{});
constexpr auto L = detail::tight_length(num) + (to_big_int(num) == big_int<1, T>{});
return detail::take_first<T>(num, std::make_index_sequence<L>{});
}
}

} // end of cbn namespace
Expand Down