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