You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

fpconv.h 851B

1234567891011121314151617181920212223242526272829303132333435
  1. #ifndef FPCONV_H
  2. #define FPCONV_H
  3. #define FPCONV_BUFLEN 32
  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. int fpconv_dtoa(double fp, char dest[FPCONV_BUFLEN], unsigned precision,
  29. bool scientific);
  30. #endif
  31. /* [1] http://florian.loitsch.com/publications/dtoa-pldi2010.pdf */