diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-04-06 12:24:22 +0100 |
---|---|---|
committer | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2019-04-06 12:24:22 +0100 |
commit | 4f9f85c6d1b7ca4bfab4599cb76e885c71ad07f6 (patch) | |
tree | 2990ad1f395a14ad4734f82b62b2c6395275da61 /contrib/fpconv/fpconv.h | |
parent | 3c918d26c6692e3f8abd524adf751fdf0d36ff62 (diff) | |
download | rspamd-4f9f85c6d1b7ca4bfab4599cb76e885c71ad07f6.tar.gz rspamd-4f9f85c6d1b7ca4bfab4599cb76e885c71ad07f6.zip |
[Feature] Import fpconv library
Source: https://github.com/night-shift/fpconv
Diffstat (limited to 'contrib/fpconv/fpconv.h')
-rw-r--r-- | contrib/fpconv/fpconv.h | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/contrib/fpconv/fpconv.h b/contrib/fpconv/fpconv.h new file mode 100644 index 000000000..58bbcccbb --- /dev/null +++ b/contrib/fpconv/fpconv.h @@ -0,0 +1,33 @@ +#ifndef FPCONV_H +#define FPCONV_H + +/* Fast and accurate double to string conversion based on Florian Loitsch's + * Grisu-algorithm[1]. + * + * Input: + * fp -> the double to convert, dest -> destination buffer. + * The generated string will never be longer than 24 characters. + * Make sure to pass a pointer to at least 24 bytes of memory. + * The emitted string will not be null terminated. + * + * Output: + * The number of written characters. + * + * Exemplary usage: + * + * void print(double d) + * { + * char buf[24 + 1] // plus null terminator + * int str_len = fpconv_dtoa(d, buf); + * + * buf[str_len] = '\0'; + * printf("%s", buf); + * } + * + */ + +int fpconv_dtoa(double fp, char dest[24]); + +#endif + +/* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */ |