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 
8 #ifndef SkFloatToDecimal_DEFINED
9 #define SkFloatToDecimal_DEFINED
10 
11 constexpr unsigned kMaximumSkFloatToDecimalLength = 49;
12 
13 /** \fn SkFloatToDecimal
14     Convert a float into a decimal string.
15 
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.
20 
21     INFINITY and -INFINITY are rounded to FLT_MAX and -FLT_MAX.
22 
23     NAN values are converted to 0.
24 
25     This function will always add a terminating '\0' to the output.
26 
27     @param value  Any floating-point number
28     @param output The buffer to write the string into.  Must be non-null.
29 
30     @return strlen(output)
31 */
32 unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength]);
33 
34 #endif  // SkFloatToDecimal_DEFINED
35