7 #if defined(KSeExpr_HAVE_CHARCONV_WITH_DOUBLES)
14 auto [
p, ec] = std::from_chars(num, num + std::strlen(num), v);
15 if (ec == std::errc()) {
25 auto [
p, ec] = std::from_chars(num.data(), num.data() + num.size(), v);
26 if (ec == std::errc()) {
36 auto [
p, ec] = std::from_chars(num.data(), num.data() + num.size(), v);
37 if (ec == std::errc()) {
39 }
else if (ec == std::errc::result_out_of_range) {
40 throw std::out_of_range {
"KSeExpr::Utils::strtol: out of range"};
42 throw std::invalid_argument {
"KSeExpr::Utils::strtol: impossible to parse the given number"};
58 double_t int_part = 0.0;
59 double_t frac_part = 0.0;
60 bool has_frac =
false;
67 }
else if (*num ==
'+') {
71 while (*num !=
'\0') {
72 if (*num >=
'0' && *num <=
'9') {
73 int_part = int_part * 10 + (*num -
'0');
74 }
else if (*num ==
'.') {
78 }
else if (*num ==
'e') {
89 double_t frac_exp = 0.1;
91 while (*num !=
'\0') {
92 if (*num >=
'0' && *num <=
'9') {
93 frac_part += frac_exp * (*num -
'0');
95 }
else if (*num ==
'e') {
107 double_t exp_part = 1.0;
108 if (*num !=
'\0' && has_exp) {
113 }
else if (*num ==
'+') {
118 while (*num !=
'\0') {
119 if (*num >=
'0' && *num <=
'9') {
120 e = e * 10 + *num -
'0';
128 exp_part = pow(exp_sign * e, 10);
131 return sign * (int_part + frac_part) * exp_part;
143 const auto result {
std::strtol(num.c_str(), &ptr, 10)};
144 if (ptr == num.c_str())
145 throw std::invalid_argument {
"KSeExpr::Utils::atoi: impossible to parse the given number"};
146 else if (ptr != num.c_str() + num.size())
147 throw std::invalid_argument {
"KSeExpr::Utils::atoi: the string had invalid extra characters"};
148 else if (errno == ERANGE)
149 throw std::out_of_range {
"KSeExpr::Utils::atoi: out of range"};
173 #if defined(KSeExpr_HAVE_DYNAMIC_DISPATCH)
174 KSeExpr_SSE41 double_t
round(double_t val)
176 return _mm_cvtsd_f64(_mm_round_sd(_mm_set_sd(0.0), _mm_set_sd(val), _MM_FROUND_TO_NEAREST_INT));
179 KSeExpr_SSE41 double_t
floor(double_t val)
181 return _mm_cvtsd_f64(_mm_floor_sd(_mm_set_sd(0.0), _mm_set_sd(val)));
static constexpr std::array< int, 514 > p
KSeExpr_DEFAULT double_t round(double_t val)
KSeExpr_DEFAULT double_t floor(double_t val)
int32_t strtol(const char *num)
double_t atof(const char *num)