From f862800d3e461efc8e34cff397a3c55e51c37849 Mon Sep 17 00:00:00 2001 From: Jan Breuer <jan.breuer@jaybee.cz> Date: 周六, 18 4月 2015 19:55:14 +0800 Subject: [PATCH] avr-libc double to string conversion --- libscpi/inc/scpi/config.h | 12 ++++++++++++ libscpi/src/utils.c | 2 +- 2 files changed, 13 insertions(+), 1 deletions(-) diff --git a/libscpi/inc/scpi/config.h b/libscpi/inc/scpi/config.h index 578d0e8..b35b22c 100644 --- a/libscpi/inc/scpi/config.h +++ b/libscpi/inc/scpi/config.h @@ -63,6 +63,11 @@ #define HAVE_STRNICMP 0 #endif +/* AVR libc */ +#if defined(__AVR_LIBC_VERSION__) +#define HAVE_DTOSTRE +#endif + /* ======== test strnlen ======== */ #ifndef HAVE_STRNLEN #define HAVE_STRNLEN 1 @@ -92,6 +97,13 @@ #define SCPI_strncasecmp(s1, s2, l) OUR_strncasecmp((s1), (s2), (l)) #endif +#if HAVE_DTOSTRE +#define SCPI_doubleToStr(v, s, l) strlen(dtostre((v), (s), 6, DTOSTR_PLUS_SIGN | DTOSTRE_ALWAYS_SIGN | DTOSTR_UPPERCASE)) +#else +#define SCPI_doubleToStr(v, s, l) snprintf((s), (l), "%lg", (v)) +#endif + + #ifdef __cplusplus } #endif diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index 26670b9..c40ddb6 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -138,7 +138,7 @@ * @return number of bytes written to str (without '\0') */ size_t doubleToStr(double val, char * str, size_t len) { - return snprintf(str, len, "%lg", val); + return SCPI_doubleToStr(val, str, len); } /** -- Gitblit v1.9.1