]> git.street.me.uk Git - andy/viking.git/blob - src/misc/fpconv.h
SF Bugs#22: Fix changing coordinates when saving and exporting
[andy/viking.git] / src / misc / fpconv.h
1 #ifndef FPCONV_H
2 #define FPCONV_H
3
4 /* Fast and accurate double to string conversion based on Florian Loitsch's
5  * Grisu-algorithm[1].
6  *
7  * Input:
8  * fp -> the double to convert, dest -> destination buffer.
9  * The generated string will never be longer than 24 characters.
10  * Make sure to pass a pointer to at least 24 bytes of memory.
11  * The emitted string will not be null terminated.
12  *
13  * Output:
14  * The number of written characters.
15  *
16  * Exemplary usage:
17  *
18  * void print(double d)
19  * {
20  *      char buf[24 + 1] // plus null terminator
21  *      int str_len = fpconv_dtoa(d, buf);
22  *
23  *      buf[str_len] = '\0';
24  *      printf("%s", buf);
25  * }
26  *
27  */
28
29 int fpconv_dtoa(double fp, char dest[24]);
30
31 #endif
32
33 /* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */