diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2026-01-21 22:40:55 +0100 |
| commit | 5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda (patch) | |
| tree | 1acdfa5220cd13b7be43a2a01368e80d306473ca /examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp | |
| parent | c7ab12bba64d9c20ccd79b132dac475f7bc3923e (diff) | |
| download | crep-5d8dfe892a2ea89f706ee140c3bdcfd89fe03fda.tar.gz | |
Add Redis source code for testing
Diffstat (limited to 'examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp')
| -rw-r--r-- | examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp b/examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp new file mode 100644 index 0000000..7f4235c --- /dev/null +++ b/examples/redis-unstable/deps/fast_float/fast_float_strtod.cpp | |||
| @@ -0,0 +1,32 @@ | |||
| 1 | #include "fast_float.h" | ||
| 2 | #include <iostream> | ||
| 3 | #include <string> | ||
| 4 | #include <system_error> | ||
| 5 | #include <cerrno> | ||
| 6 | |||
| 7 | /* Convert NPTR to a double using the fast_float library. | ||
| 8 | * | ||
| 9 | * This function behaves similarly to the standard strtod function, converting | ||
| 10 | * the initial portion of the string pointed to by `nptr` to a `double` value, | ||
| 11 | * using the fast_float library for high performance. If the conversion fails, | ||
| 12 | * errno is set to EINVAL error code. | ||
| 13 | * | ||
| 14 | * @param nptr A pointer to the null-terminated byte string to be interpreted. | ||
| 15 | * @param endptr A pointer to a pointer to character. If `endptr` is not NULL, | ||
| 16 | * it will point to the character after the last character used | ||
| 17 | * in the conversion. | ||
| 18 | * @return The converted value as a double. If no valid conversion could | ||
| 19 | * be performed, returns 0.0. | ||
| 20 | * If ENDPTR is not NULL, a pointer to the character after the last one used | ||
| 21 | * in the number is put in *ENDPTR. */ | ||
| 22 | extern "C" double fast_float_strtod(const char *nptr, char **endptr) { | ||
| 23 | double result = 0.0; | ||
| 24 | auto answer = fast_float::from_chars(nptr, nptr + strlen(nptr), result); | ||
| 25 | if (answer.ec != std::errc()) { | ||
| 26 | errno = EINVAL; // Fallback to for other errors | ||
| 27 | } | ||
| 28 | if (endptr != NULL) { | ||
| 29 | *endptr = (char *)answer.ptr; | ||
| 30 | } | ||
| 31 | return result; | ||
| 32 | } | ||
