gmio_core/internal: add gmio_to_float32() which is faster than gmio_get_float32()

This commit is contained in:
Hugues Delorme 2015-11-02 10:46:42 +01:00
parent 4be2c0b3fc
commit 620930b33f

View File

@ -18,18 +18,7 @@
#include "../global.h" #include "../global.h"
#include "../stream.h" #include "../stream.h"
/* For implementation section */
#include "helper_stream.h"
#include "string.h" #include "string.h"
#include "string_utils.h"
#ifdef GMIO_STRINGPARSE_USE_FAST_ATOF
# include "fast_atof.h"
#endif
#include <errno.h>
#include <stdlib.h>
/* End for implementation section */
/*! Forward iterator over a stream /*! Forward iterator over a stream
* *
@ -103,12 +92,22 @@ gmio_bool_t gmio_checked_next_chars(
*/ */
GMIO_INLINE int gmio_get_float32(const char* str, gmio_float32_t* value_ptr); GMIO_INLINE int gmio_get_float32(const char* str, gmio_float32_t* value_ptr);
GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str);
/* /*
* -- Implementation * -- Implementation
*/ */
#include "helper_stream.h"
#include "string_utils.h"
#ifdef GMIO_STRINGPARSE_USE_FAST_ATOF
# include "fast_atof.h"
#endif
#include <errno.h>
#include <stdlib.h>
const char* gmio_current_char( const char* gmio_current_char(
const gmio_string_stream_fwd_iterator_t* it) const gmio_string_stream_fwd_iterator_t* it)
{ {
@ -174,4 +173,15 @@ int gmio_get_float32(const char* str, gmio_float32_t* value_ptr)
return (end_ptr == str || errno == ERANGE) ? -1 : 0; return (end_ptr == str || errno == ERANGE) ? -1 : 0;
} }
GMIO_INLINE gmio_float32_t gmio_to_float32(const char* str)
{
#if defined(GMIO_STRINGPARSE_USE_FAST_ATOF)
return fast_atof(str, NULL);
#elif defined(GMIO_HAVE_STRTOF_FUNC) /* Requires C99 */
return strtof(str, NULL);
#else
return (gmio_float32_t)strtod(str, NULL);
#endif
}
#endif /* GMIO_INTERNAL_STRING_PARSE_H */ #endif /* GMIO_INTERNAL_STRING_PARSE_H */