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