/* * Copyright 2017 Google Inc. * * Use of this source code is governed by a BSD-style license that can be * found in the LICENSE file. */ #include "src/utils/SkFloatToDecimal.h" #include "include/core/SkTypes.h" #include <cfloat> #include <cmath> #ifdef SK_DEBUG #include <limits.h> #endif // returns `value * pow(base, e)`, assuming `e` is positive. static double pow_by_squaring(double value, double base, int e) { … } // Return pow(10.0, e), optimized for common cases. static double pow10(int e) { … } /** Write a string into output, including a terminating '\0' (for unit testing). Return strlen(output) (for SkWStream::write) The resulting string will be in the form /[-]?([0-9]*.)?[0-9]+/ and sscanf(output, "%f", &x) will return the original value iff the value is finite. This function accepts all possible input values. Motivation: "PDF does not support [numbers] in exponential format (such as 6.02e23)." Otherwise, this function would rely on a sprintf-type function from the standard library. */ unsigned SkFloatToDecimal(float value, char output[kMaximumSkFloatToDecimalLength]) { … }