skia2/src/utils/SkFloatToDecimal.h
Hal Canary 3c36ef6be9 SkFloatToDecimal moved to src/utils
This change stages SkFloatToDecimal() for possible re-use by pdfium.

Change-Id: Iedc0c78c8a633f0b0973365d2d8b540b5443590d
Reviewed-on: https://skia-review.googlesource.com/90400
Commit-Queue: Hal Canary <halcanary@google.com>
Reviewed-by: Cary Clark <caryclark@google.com>
2018-01-03 19:59:31 +00:00

35 lines
1.0 KiB
C++

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