21#if __cpp_constexpr >= 201304
22# define CONSTEXPR14 constexpr
24# define CONSTEXPR14 inline
102 extern auto to_csd(
double decimal_value,
int places) -> std::string;
151 extern auto to_csd_i(
int decimal_value) -> std::string;
188 extern auto to_csdnnz(
double decimal_value,
unsigned int nnz) -> std::string;
224 extern auto to_csdnnz_i(
int decimal_value,
unsigned int nnz) -> std::string;
244 for (; *
csd !=
'.' && *
csd !=
'\0'; ++
csd) {
250 integral = integral * 2 + 1;
253 integral = integral * 2 - 1;
256 throw std::invalid_argument(
"Work with 0, +, -, and . only");
260 return double(integral);
263 auto decimal_value = double(integral);
270 decimal_value += scale;
273 decimal_value -= scale;
276 throw std::invalid_argument(
"Fractional part work with 0, +, and - only");
280 return decimal_value;
308 auto decimal_value = 0;
314 }
else if (digit ==
'+') {
315 decimal_value = (decimal_value << 1) + 1;
316 }
else if (digit ==
'-') {
317 decimal_value = (decimal_value << 1) - 1;
318 }
else if (digit ==
'.' || digit ==
'\0') {
321 throw std::invalid_argument(
"Work with 0, +, -, and . only");
325 return decimal_value;
342 auto decimal_value = 0.0;
348 }
else if (digit ==
'+') {
349 decimal_value += scale;
350 }
else if (digit ==
'-') {
351 decimal_value -= scale;
352 }
else if (digit ==
'\0') {
355 throw std::invalid_argument(
"Fractional part work with 0, +, and - only");
360 return decimal_value;
405 return double(integral);
409 return double(integral) + fractional;
#define CONSTEXPR14
Definition csd.hpp:24
CONSTEXPR14 auto to_decimal_i(const char *csd) -> int
Convert CSD string to integer.
Definition csd.hpp:444
constexpr int MAX_DECIMAL_PLACES
Maximum number of decimal places supported by CSD conversion.
Definition csd.hpp:34
CONSTEXPR14 auto to_decimal_using_switch(const char *csd) -> double
Definition csd.hpp:241
CONSTEXPR14 auto to_decimal_integral(const char *&csd) -> int
Convert the integral part of a CSD string to a decimal.
Definition csd.hpp:307
CONSTEXPR14 auto to_decimal(const char *csd) -> double
Convert the CSD string to a decimal.
Definition csd.hpp:401
auto to_csd_i(int decimal_value) -> std::string
auto to_csdnnz_i(int decimal_value, unsigned int nnz) -> std::string
Convert an integer to CSD with limited non-zero digits.
auto to_csdnnz(double decimal_value, unsigned int nnz) -> std::string
Convert a floating-point number to CSD with limited non-zero digits.
auto to_csd(double decimal_value, int places) -> std::string
CONSTEXPR14 auto to_decimal_fractional(const char *csd) -> double
Convert the fractional part of a CSD string to a decimal.
Definition csd.hpp:341
constexpr unsigned int MIN_NONZERO_DIGITS
Minimum value for non-zero digit count in CSDNNZ functions.
Definition csd.hpp:37