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 793B

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