From cb38dba9fe0344b02f4b183152263fe3c0066290 Mon Sep 17 00:00:00 2001 From: Iztok Jeras <iztok.jeras@redpitaya.com> Date: ćšć, 08 10æ 2015 03:00:34 +0800 Subject: [PATCH] integer parse: added support for float --- libscpi/src/utils.c | 26 ++++++++++++++++++++++++-- 1 files changed, 24 insertions(+), 2 deletions(-) diff --git a/libscpi/src/utils.c b/libscpi/src/utils.c index 456e8f3..205bea6 100644 --- a/libscpi/src/utils.c +++ b/libscpi/src/utils.c @@ -245,7 +245,18 @@ } /** - * Converts double value to string + * Converts float (32 bit) value to string + * @param val long value + * @param str converted textual representation + * @param len string buffer length + * @return number of bytes written to str (without '\0') + */ +size_t SCPI_FloatToStr(float val, char * str, size_t len) { + return SCPIDEFINE_floatToStr(val, str, len); +} + +/** + * Converts double (64 bit) value to string * @param val double value * @param str converted textual representation * @param len string buffer length @@ -303,9 +314,20 @@ return endptr - str; } +/** + * Converts string to float (32 bit) representation + * @param str string value + * @param val float result + * @return number of bytes used in string + */ +size_t strToFloat(const char * str, float * val) { + char * endptr; + *val = strtof(str, &endptr); + return endptr - str; +} /** - * Converts string to double representation + * Converts string to double (64 bit) representation * @param str string value * @param val double result * @return number of bytes used in string -- Gitblit v1.9.1