diff options
author | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-05-04 00:39:35 +0300 |
---|---|---|
committer | Costa Tsaousis (ktsaou) <costa@tsaousis.gr> | 2017-05-04 00:39:35 +0300 |
commit | b689036d47ee0004f1ac11e888073d0557e28ca9 (patch) | |
tree | d416d9ed6d71bed8b744e957c9dc973ee7ff88db /src/inlined.h | |
parent | c93f4240e3a65e3f63b3f82ed651e4caae106b9d (diff) |
operational statsd with custom apps
Diffstat (limited to 'src/inlined.h')
-rw-r--r-- | src/inlined.h | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/src/inlined.h b/src/inlined.h index 0dc11c9509..858ba31abc 100644 --- a/src/inlined.h +++ b/src/inlined.h @@ -123,6 +123,82 @@ static inline unsigned long long str2ull(const char *s) { return n; } +static inline long long str2ll(const char *s, char **endptr) { + int negative = 0; + + if(unlikely(*s == '-')) { + s++; + negative = 1; + } + else if(unlikely(*s == '+')) + s++; + + long long n = 0; + char c; + for(c = *s; c >= '0' && c <= '9' ; c = *(++s)) { + n *= 10; + n += c - '0'; + } + + if(unlikely(endptr)) + *endptr = (char *)s; + + if(unlikely(negative)) + return -n; + else + return n; +} + +static inline long double str2ld(const char *s, char **endptr) { + int negative = 0; + const char *start = s; + unsigned long long integer_part = 0; + unsigned long decimal_part = 0; + size_t decimal_digits = 0; + + if(unlikely(*s == '-')) { + s++; + negative = 1; + } + else if(unlikely(*s == '+')) + s++; + + while (*s >= '0' && *s <= '9') { + integer_part = (integer_part * 10) + (*s - '0'); + s++; + } + + if(unlikely(*s == '.')) { + decimal_part = 0; + s++; + + while (*s >= '0' && *s <= '9') { + decimal_part = (decimal_part * 10) + (*s - '0'); + s++; + decimal_digits++; + } + } + + if(unlikely(*s == 'e' || *s == 'E')) + return strtold(start, endptr); + + if(unlikely(endptr)) + *endptr = (char *)s; + + if(unlikely(negative)) { + if(unlikely(decimal_digits)) + return -((long double)integer_part + (long double)decimal_part / powl(10.0, decimal_digits)); + else + return -((long double)integer_part); + } + else { + if(unlikely(decimal_digits)) + return (long double)integer_part + (long double)decimal_part / powl(10.0, decimal_digits); + else + return (long double)integer_part; + } +} + #ifdef NETDATA_STRCMP_OVERRIDE #ifdef strcmp #undef strcmp |