File: fpconv.h

package info (click to toggle)
rspamd 2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,408 kB
  • sloc: ansic: 225,036; javascript: 29,185; cpp: 16,036; perl: 2,867; asm: 2,512; pascal: 1,607; python: 1,128; sh: 406; sql: 313; makefile: 130; xml: 74
file content (35 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef FPCONV_H
#define FPCONV_H

#define FPCONV_BUFLEN 32
/* 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[FPCONV_BUFLEN], unsigned precision,
		bool scientific);

#endif

/* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */