38 HEDLEY_CONST CONSTEXPR_14
39 long double pow10(
const T& n) noexcept {
40 long double multiplicand = n > 0 ? 10 : 0.1,
44 T iterations = n > 0 ? n : -n;
46 for (T i = 0; i < iterations; i++) {
55 HEDLEY_CONST CONSTEXPR_14
56 long double pow10(
const unsigned& n) noexcept {
57 long double multiplicand = n > 0 ? 10 : 0.1,
60 for (
unsigned i = 0; i < n; i++) {
67 #ifndef DOXYGEN_SHOULD_SKIP_THIS
69 constexpr
DataType int_type_arr[8] = {
82 static_assert(std::is_integral<T>::value,
"T should be an integral type.");
83 static_assert(
sizeof(T) <= 8,
"Byte size must be no greater than 8.");
84 return int_type_arr[
sizeof(T) - 1];
102 template<
size_t Bytes>
104 static_assert(Bytes == 1 || Bytes == 2 || Bytes == 4 || Bytes == 8,
105 "Bytes must be a power of 2 below 8.");
108 return (
long double)std::numeric_limits<signed char>::max();
112 return (
long double)std::numeric_limits<short>::max();
116 return (
long double)std::numeric_limits<int>::max();
120 return (
long double)std::numeric_limits<long int>::max();
124 return (
long double)std::numeric_limits<long long int>::max();
127 HEDLEY_UNREACHABLE();
133 template<
size_t Bytes>
135 static_assert(Bytes == 1 || Bytes == 2 || Bytes == 4 || Bytes == 8,
136 "Bytes must be a power of 2 below 8.");
139 return (
long double)std::numeric_limits<unsigned char>::max();
143 return (
long double)std::numeric_limits<unsigned short>::max();
147 return (
long double)std::numeric_limits<unsigned int>::max();
151 return (
long double)std::numeric_limits<unsigned long int>::max();
155 return (
long double)std::numeric_limits<unsigned long long int>::max();
158 HEDLEY_UNREACHABLE();
189 HEDLEY_PRIVATE CONSTEXPR_14
192 const long double& coeff,
193 long double *
const out) {
194 long double exponent = 0;
195 auto result =
data_type(exponential_part, &exponent);
199 if (out) *out = coeff *
pow10(exponent);
209 HEDLEY_PRIVATE HEDLEY_PURE CONSTEXPR_14
243 bool ws_allowed =
true,
246 digit_allowed =
true,
250 unsigned places_after_decimal = 0;
251 long double integral_part = 0,
254 for (
size_t i = 0, ilen = in.size(); i < ilen; i++) {
255 const char& current = in[i];
260 if (isdigit(in[i - 1])) {
261 digit_allowed =
false;
289 if (prob_float || (i && i + 1 < ilen && isdigit(in[i - 1]))) {
290 size_t exponent_start_idx = i + 1;
294 if (in[i + 1] ==
'+') {
295 exponent_start_idx++;
299 in.substr(exponent_start_idx),
300 neg_allowed ? integral_part + decimal_part : -(integral_part + decimal_part),
308 short digit =
static_cast<short>(current -
'0');
309 if (digit >= 0 && digit <= 9) {
320 decimal_part += digit /
pow10(++places_after_decimal);
322 integral_part = (integral_part * 10) + digit;
332 long double number = integral_part + decimal_part;
334 *out = neg_allowed ? number : -number;
A standalone header file containing shared code.
#define IF_CONSTEXPR
Expands to if constexpr in C++17 and if otherwise.
CONSTEXPR_VALUE_14 long double CSV_INT16_MAX
Largest number that can be stored in a 16-bit integer.
CONSTEXPR_VALUE_14 long double CSV_INT32_MAX
Largest number that can be stored in a 32-bit integer.
CONSTEXPR_VALUE_14 long double CSV_UINT16_MAX
Largest number that can be stored in a 16-bit unsigned integer.
CONSTEXPR_VALUE_14 long double CSV_UINT32_MAX
Largest number that can be stored in a 32-bit unsigned integer.
HEDLEY_PRIVATE CONSTEXPR_14 DataType _process_potential_exponential(csv::string_view exponential_part, const long double &coeff, long double *const out)
Given a pointer to the start of what is start of the exponential part of a number written (possibly) ...
CONSTEXPR_VALUE_14 long double CSV_INT64_MAX
Largest number that can be stored in a 64-bit integer.
CONSTEXPR_VALUE_14 long double CSV_INT8_MAX
Largest number that can be stored in a 8-bit integer.
CONSTEXPR_VALUE_14 long double CSV_UINT64_MAX
Largest number that can be stored in a 64-bit unsigned integer.
CONSTEXPR_VALUE_14 long double CSV_UINT8_MAX
Largest number that can be stored in a 8-bit ungisned integer.
CONSTEXPR_14 DataType data_type(csv::string_view in, long double *const out)
Distinguishes numeric from other text values.
HEDLEY_CONST CONSTEXPR_14 long double pow10(const T &n) noexcept
Compute 10 to the power of n.
HEDLEY_PRIVATE HEDLEY_PURE CONSTEXPR_14 DataType _determine_integral_type(const long double &number) noexcept
Given the absolute value of an integer, determine what numeric type it fits in.
CONSTEXPR_14 long double get_uint_max()
Given a byte size, return the largest number than can be stored in an unsigned integer of that size.
CONSTEXPR_14 long double get_int_max()
Given a byte size, return the largest number than can be stored in an integer of that size.
The all encompassing namespace.
DataType
Enumerates the different CSV field types that are recognized by this library.
@ CSV_INT64
64-bit integer (long long on MSVC/GCC)
@ CSV_DOUBLE
Floating point value.
@ CSV_INT16
16-bit integer (short on MSVC/GCC)
@ CSV_INT32
32-bit integer (int on MSVC/GCC)
@ CSV_STRING
Non-numeric string.
nonstd::string_view string_view
The string_view class used by this library.