SkFloatToDecimal.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright 2017 Google Inc.
  3. *
  4. * Use of this source code is governed by a BSD-style license that can be
  5. * found in the LICENSE file.
  6. */
  7. #ifndef SkFloatToDecimal_DEFINED
  8. #define SkFloatToDecimal_DEFINED
  9. constexpr unsigned kMaximumSkFloatToDecimalLength = 49;
  10. /** \fn SkFloatToDecimal
  11. Convert a float into a decimal string.
  12. The resulting string will be in the form `[-]?([0-9]*\.)?[0-9]+` (It does
  13. not use scientific notation.) and `sscanf(output, "%f", &x)` will return
  14. the original value if the value is finite. This function accepts all
  15. possible input values.
  16. INFINITY and -INFINITY are rounded to FLT_MAX and -FLT_MAX.
  17. NAN values are converted to 0.
  18. This function will always add a terminating '\0' to the output.
  19. @param value Any floating-point number
  20. @param output The buffer to write the string into. Must be non-null.
  21. @return strlen(output)
  22. */
  23. unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength]);
  24. #endif // SkFloatToDecimal_DEFINED