String and Number Utilities
This is a collection of the most basic string and number utilities that are used throughout aarith.
String Utilities
Header aarith/core/core_string_utils
-
namespace aarith
Functions
-
inline constexpr auto number_of_decimal_digits(size_t n_bits) -> size_t
Computes an approximation of the decimal deigits an n_bits number will use.
- Parameters
n_bits – The number of bits in the number
- Returns
The approximation of the number of decimal digits the n_bits number will have
- template<class T, class U> constexpr auto rounded_integer_division (T dividend, U divisor) -> decltype(T
Division with subsequent ceil oberation.
Computes ceil(dividend/divisor)
- Template Parameters
T – Type of the dividend
U – Type of the divisor
- Parameters
dividend – The actual dividend
divisor – The actual divisor
- Returns
Returns ceil(dividend/divisor)
-
WordType auto to_binary(const word_array<Width, WordType> &value) -> std::string
-
template<size_t W, typename WordType, template<size_t, typename> class WA, typename = std::enable_if_t<is_word_array_v<WA<W, WordType>> && !is_integral_v<WA<W, WordType>>>>
auto operator<<(std::ostream &out, const WA<W, WordType> &value) -> std::ostream& Outputs a
word_array
to an output stream using the convenient << operator form.- Template Parameters
W – Width of the word array
WordType – The type used to store the actual data
WA – Generic word array type
Variables
- U
-
inline constexpr auto number_of_decimal_digits(size_t n_bits) -> size_t
Number Utilities
Header aarith/core/core_number_utils.hpp
-
namespace aarith
Functions
-
template<unsigned Base, unsigned Value>
constexpr double log() Constexpr version of log.
This method is necessary as not all compilers already come with a constexpr ready math library.
Note
Only two values needed by aarith are epxlictly stored!
- Template Parameters
Base – The base of the loarithm
Value – The value whose logarithm is to be computed
- Returns
The logarithm of Value base Base
-
template<>
constexpr double log<2, 10>() The constexpr value of log_2(10)
- Returns
log_2(10)
-
template<>
constexpr double log<10, 2>() The constexpr value of log_10(2)
- Returns
log_10(2)
-
template<class Result>
constexpr Result ceil(double num) Constexpr version of the ceil operation.
This method is only necessary as not all compilers already have an constexpr ready math library.
- Template Parameters
Result – Type for the result
- Parameters
num – The number to round down
- Returns
num rounded down
-
constexpr size_t pow(const size_t base, const size_t exponent)
Exponentiation function.
Note
This function does not make any attempts to be fast or to prevent overflows!
Note
If exponent equals std::numeric_limits<size_t>::max(), this method throws an exception, unless base equals zero
- Parameters
base –
exponent –
- Returns
The base to the power of the exponent
-
constexpr size_t first_set_bit(const size_t n)
-
constexpr size_t floor_to_pow(const size_t n)
Rounds down to the next power of two.
TODO (keszocze) remove this method when clang supports constexpr for std::log2 and std::floor
- Parameters
n – The number to round
- Returns
The largest number m=2^k for some k such that m <= n
-
template<unsigned Base, unsigned Value>