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.
73 {
74
75
76
77
79
80
81
83
84
85
86
87
88
89
90
91
92
93 char* output_ptr = &
output[0];
95
96
97
98
99
100
101 if (
value == INFINITY) {
103 }
104 if (
value == -INFINITY) {
106 }
108
109
110 *output_ptr++ = '0';
111 *output_ptr = '\0';
112 return static_cast<unsigned>(output_ptr -
output);
113 }
115 *output_ptr++ = '-';
117 }
119
120 int binaryExponent;
121 (void)std::frexp(
value, &binaryExponent);
122 static const double kLog2 = 0.3010299956639812;
123 int decimalExponent =
static_cast<int>(
std::floor(kLog2 * binaryExponent));
124 int decimalShift = decimalExponent - 8;
125 double power =
pow10(-decimalShift);
127 int d =
static_cast<int>(
value * power + 0.5);
128
131
132 decimalShift = decimalExponent - 7;
133
134
135 d =
static_cast<int>(
value * (power * 0.1) + 0.5);
137 }
138 while (
d % 10 == 0) {
140 ++decimalShift;
141 }
143
145 int bufferIndex = 0;
146 do {
147 buffer[bufferIndex++] =
d % 10;
151 if (decimalShift >= 0) {
152 do {
153 --bufferIndex;
154 *output_ptr++ =
'0' +
buffer[bufferIndex];
155 } while (bufferIndex);
156 for (
int i = 0;
i < decimalShift; ++
i) {
157 *output_ptr++ = '0';
158 }
159 } else {
160 int placesBeforeDecimal = bufferIndex + decimalShift;
161 if (placesBeforeDecimal > 0) {
162 while (placesBeforeDecimal-- > 0) {
163 --bufferIndex;
164 *output_ptr++ =
'0' +
buffer[bufferIndex];
165 }
166 *output_ptr++ = '.';
167 } else {
168 *output_ptr++ = '.';
169 int placesAfterDecimal = -placesBeforeDecimal;
170 while (placesAfterDecimal-- > 0) {
171 *output_ptr++ = '0';
172 }
173 }
174 while (bufferIndex > 0) {
175 --bufferIndex;
176 *output_ptr++ =
'0' +
buffer[bufferIndex];
177 if (output_ptr ==
end) {
178 break;
179
180
181 }
182 }
183 }
185 *output_ptr = '\0';
186 return static_cast<unsigned>(output_ptr -
output);
187}
static double pow10(int e)
constexpr unsigned kMaximumSkFloatToDecimalLength
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
SINT bool isfinite(const Vec< N, T > &v)
SIN Vec< N, float > floor(const Vec< N, float > &x)