Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: Source/wtf/dtoa/double-conversion.h

Issue 20300002: Fix trailing whitespace in .cpp, .h, and .idl files (ex. Source/core) (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « Source/wtf/dtoa/double.h ('k') | Source/wtf/dtoa/fast-dtoa.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2010 the V8 project authors. All rights reserved. 1 // Copyright 2010 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 15 matching lines...) Expand all
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 #ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ 28 #ifndef DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
29 #define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ 29 #define DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
30 30
31 #include "wtf/dtoa/utils.h" 31 #include "wtf/dtoa/utils.h"
32 32
33 namespace WTF { 33 namespace WTF {
34 34
35 namespace double_conversion { 35 namespace double_conversion {
36 36
37 class DoubleToStringConverter { 37 class DoubleToStringConverter {
38 public: 38 public:
39 // When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint 39 // When calling ToFixed with a double > 10^kMaxFixedDigitsBeforePoint
40 // or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the 40 // or a requested_digits parameter > kMaxFixedDigitsAfterPoint then the
41 // function returns false. 41 // function returns false.
42 static const int kMaxFixedDigitsBeforePoint = 60; 42 static const int kMaxFixedDigitsBeforePoint = 60;
43 static const int kMaxFixedDigitsAfterPoint = 60; 43 static const int kMaxFixedDigitsAfterPoint = 60;
44 44
45 // When calling ToExponential with a requested_digits 45 // When calling ToExponential with a requested_digits
46 // parameter > kMaxExponentialDigits then the function returns false. 46 // parameter > kMaxExponentialDigits then the function returns false.
47 static const int kMaxExponentialDigits = 120; 47 static const int kMaxExponentialDigits = 120;
48 48
49 // When calling ToPrecision with a requested_digits 49 // When calling ToPrecision with a requested_digits
50 // parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDi gits 50 // parameter < kMinPrecisionDigits or requested_digits > kMaxPrecisionDi gits
51 // then the function returns false. 51 // then the function returns false.
52 static const int kMinPrecisionDigits = 1; 52 static const int kMinPrecisionDigits = 1;
53 static const int kMaxPrecisionDigits = 120; 53 static const int kMaxPrecisionDigits = 120;
54 54
55 enum Flags { 55 enum Flags {
56 NO_FLAGS = 0, 56 NO_FLAGS = 0,
57 EMIT_POSITIVE_EXPONENT_SIGN = 1, 57 EMIT_POSITIVE_EXPONENT_SIGN = 1,
58 EMIT_TRAILING_DECIMAL_POINT = 2, 58 EMIT_TRAILING_DECIMAL_POINT = 2,
59 EMIT_TRAILING_ZERO_AFTER_POINT = 4, 59 EMIT_TRAILING_ZERO_AFTER_POINT = 4,
60 UNIQUE_ZERO = 8 60 UNIQUE_ZERO = 8
61 }; 61 };
62 62
63 // Flags should be a bit-or combination of the possible Flags-enum. 63 // Flags should be a bit-or combination of the possible Flags-enum.
64 // - NO_FLAGS: no special flags. 64 // - NO_FLAGS: no special flags.
65 // - EMIT_POSITIVE_EXPONENT_SIGN: when the number is converted into exp onent 65 // - EMIT_POSITIVE_EXPONENT_SIGN: when the number is converted into exp onent
66 // form, emits a '+' for positive exponents. Example: 1.2e+2. 66 // form, emits a '+' for positive exponents. Example: 1.2e+2.
67 // - EMIT_TRAILING_DECIMAL_POINT: when the input number is an integer a nd is 67 // - EMIT_TRAILING_DECIMAL_POINT: when the input number is an integer a nd is
68 // converted into decimal format then a trailing decimal point is app ended. 68 // converted into decimal format then a trailing decimal point is app ended.
69 // Example: 2345.0 is converted to "2345.". 69 // Example: 2345.0 is converted to "2345.".
70 // - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point 70 // - EMIT_TRAILING_ZERO_AFTER_POINT: in addition to a trailing decimal point
71 // emits a trailing '0'-character. This flag requires the 71 // emits a trailing '0'-character. This flag requires the
72 // EXMIT_TRAILING_DECIMAL_POINT flag. 72 // EXMIT_TRAILING_DECIMAL_POINT flag.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 decimal_in_shortest_high_(decimal_in_shortest_high), 122 decimal_in_shortest_high_(decimal_in_shortest_high),
123 max_leading_padding_zeroes_in_precision_mode_( 123 max_leading_padding_zeroes_in_precision_mode_(
124 max_leading_padding_zeroes _in_precision_mode), 124 max_leading_padding_zeroes _in_precision_mode),
125 max_trailing_padding_zeroes_in_precision_mode_( 125 max_trailing_padding_zeroes_in_precision_mode_(
126 max_trailing_padding_zero es_in_precision_mode) { 126 max_trailing_padding_zero es_in_precision_mode) {
127 // When 'trailing zero after the point' is set, then 'trailing point ' 127 // When 'trailing zero after the point' is set, then 'trailing point '
128 // must be set too. 128 // must be set too.
129 ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) || 129 ASSERT(((flags & EMIT_TRAILING_DECIMAL_POINT) != 0) ||
130 !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0)); 130 !((flags & EMIT_TRAILING_ZERO_AFTER_POINT) != 0));
131 } 131 }
132 132
133 // Returns a converter following the EcmaScript specification. 133 // Returns a converter following the EcmaScript specification.
134 static const DoubleToStringConverter& EcmaScriptConverter(); 134 static const DoubleToStringConverter& EcmaScriptConverter();
135 135
136 // Computes the shortest string of digits that correctly represent the i nput 136 // Computes the shortest string of digits that correctly represent the i nput
137 // number. Depending on decimal_in_shortest_low and decimal_in_shortest_ high 137 // number. Depending on decimal_in_shortest_low and decimal_in_shortest_ high
138 // (see constructor) it then either returns a decimal representation, or an 138 // (see constructor) it then either returns a decimal representation, or an
139 // exponential representation. 139 // exponential representation.
140 // Example with decimal_in_shortest_low = -6, 140 // Example with decimal_in_shortest_low = -6,
141 // decimal_in_shortest_high = 21, 141 // decimal_in_shortest_high = 21,
142 // EMIT_POSITIVE_EXPONENT_SIGN activated, and 142 // EMIT_POSITIVE_EXPONENT_SIGN activated, and
143 // EMIT_TRAILING_DECIMAL_POINT deactived: 143 // EMIT_TRAILING_DECIMAL_POINT deactived:
144 // ToShortest(0.000001) -> "0.000001" 144 // ToShortest(0.000001) -> "0.000001"
145 // ToShortest(0.0000001) -> "1e-7" 145 // ToShortest(0.0000001) -> "1e-7"
146 // ToShortest(111111111111111111111.0) -> "111111111111111110000" 146 // ToShortest(111111111111111111111.0) -> "111111111111111110000"
147 // ToShortest(100000000000000000000.0) -> "100000000000000000000" 147 // ToShortest(100000000000000000000.0) -> "100000000000000000000"
148 // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21" 148 // ToShortest(1111111111111111111111.0) -> "1.1111111111111111e+21"
149 // 149 //
150 // Note: the conversion may round the output if the returned string 150 // Note: the conversion may round the output if the returned string
151 // is accurate enough to uniquely identify the input-number. 151 // is accurate enough to uniquely identify the input-number.
152 // For example the most precise representation of the double 9e59 equals 152 // For example the most precise representation of the double 9e59 equals
153 // "899999999999999918767229449717619953810131273674690656206848", but 153 // "899999999999999918767229449717619953810131273674690656206848", but
154 // the converter will return the shorter (but still correct) "9e59". 154 // the converter will return the shorter (but still correct) "9e59".
155 // 155 //
156 // Returns true if the conversion succeeds. The conversion always succee ds 156 // Returns true if the conversion succeeds. The conversion always succee ds
157 // except when the input value is special and no infinity_symbol or 157 // except when the input value is special and no infinity_symbol or
158 // nan_symbol has been given to the constructor. 158 // nan_symbol has been given to the constructor.
159 bool ToShortest(double value, StringBuilder* result_builder) const; 159 bool ToShortest(double value, StringBuilder* result_builder) const;
160 160
161 161
162 // Computes a decimal representation with a fixed number of digits after the 162 // Computes a decimal representation with a fixed number of digits after the
163 // decimal point. The last emitted digit is rounded. 163 // decimal point. The last emitted digit is rounded.
164 // 164 //
165 // Examples: 165 // Examples:
166 // ToFixed(3.12, 1) -> "3.1" 166 // ToFixed(3.12, 1) -> "3.1"
167 // ToFixed(3.1415, 3) -> "3.142" 167 // ToFixed(3.1415, 3) -> "3.142"
168 // ToFixed(1234.56789, 4) -> "1234.5679" 168 // ToFixed(1234.56789, 4) -> "1234.5679"
169 // ToFixed(1.23, 5) -> "1.23000" 169 // ToFixed(1.23, 5) -> "1.23000"
170 // ToFixed(0.1, 4) -> "0.1000" 170 // ToFixed(0.1, 4) -> "0.1000"
171 // ToFixed(1e30, 2) -> "1000000000000000019884624838656.00" 171 // ToFixed(1e30, 2) -> "1000000000000000019884624838656.00"
(...skipping 16 matching lines...) Expand all
188 // - the input value is special and no infinity_symbol or nan_symbol h as 188 // - the input value is special and no infinity_symbol or nan_symbol h as
189 // been provided to the constructor, 189 // been provided to the constructor,
190 // - 'value' > 10^kMaxFixedDigitsBeforePoint, or 190 // - 'value' > 10^kMaxFixedDigitsBeforePoint, or
191 // - 'requested_digits' > kMaxFixedDigitsAfterPoint. 191 // - 'requested_digits' > kMaxFixedDigitsAfterPoint.
192 // The last two conditions imply that the result will never contain more than 192 // The last two conditions imply that the result will never contain more than
193 // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint charac ters 193 // 1 + kMaxFixedDigitsBeforePoint + 1 + kMaxFixedDigitsAfterPoint charac ters
194 // (one additional character for the sign, and one for the decimal point ). 194 // (one additional character for the sign, and one for the decimal point ).
195 bool ToFixed(double value, 195 bool ToFixed(double value,
196 int requested_digits, 196 int requested_digits,
197 StringBuilder* result_builder) const; 197 StringBuilder* result_builder) const;
198 198
199 // Computes a representation in exponential format with requested_digits 199 // Computes a representation in exponential format with requested_digits
200 // after the decimal point. The last emitted digit is rounded. 200 // after the decimal point. The last emitted digit is rounded.
201 // If requested_digits equals -1, then the shortest exponential represen tation 201 // If requested_digits equals -1, then the shortest exponential represen tation
202 // is computed. 202 // is computed.
203 // 203 //
204 // Examples with EMIT_POSITIVE_EXPONENT_SIGN deactivated, and 204 // Examples with EMIT_POSITIVE_EXPONENT_SIGN deactivated, and
205 // exponent_character set to 'e'. 205 // exponent_character set to 'e'.
206 // ToExponential(3.12, 1) -> "3.1e0" 206 // ToExponential(3.12, 1) -> "3.1e0"
207 // ToExponential(5.0, 3) -> "5.000e0" 207 // ToExponential(5.0, 3) -> "5.000e0"
208 // ToExponential(0.001, 2) -> "1.00e-3" 208 // ToExponential(0.001, 2) -> "1.00e-3"
(...skipping 11 matching lines...) Expand all
220 // - the input value is special and no infinity_symbol or nan_symbol h as 220 // - the input value is special and no infinity_symbol or nan_symbol h as
221 // been provided to the constructor, 221 // been provided to the constructor,
222 // - 'requested_digits' > kMaxExponentialDigits. 222 // - 'requested_digits' > kMaxExponentialDigits.
223 // The last condition implies that the result will never contain more th an 223 // The last condition implies that the result will never contain more th an
224 // kMaxExponentialDigits + 8 characters (the sign, the digit before the 224 // kMaxExponentialDigits + 8 characters (the sign, the digit before the
225 // decimal point, the decimal point, the exponent character, the 225 // decimal point, the decimal point, the exponent character, the
226 // exponent's sign, and at most 3 exponent digits). 226 // exponent's sign, and at most 3 exponent digits).
227 bool ToExponential(double value, 227 bool ToExponential(double value,
228 int requested_digits, 228 int requested_digits,
229 StringBuilder* result_builder) const; 229 StringBuilder* result_builder) const;
230 230
231 // Computes 'precision' leading digits of the given 'value' and returns them 231 // Computes 'precision' leading digits of the given 'value' and returns them
232 // either in exponential or decimal format, depending on 232 // either in exponential or decimal format, depending on
233 // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the 233 // max_{leading|trailing}_padding_zeroes_in_precision_mode (given to the
234 // constructor). 234 // constructor).
235 // The last computed digit is rounded. 235 // The last computed digit is rounded.
236 // 236 //
237 // Example with max_leading_padding_zeroes_in_precision_mode = 6. 237 // Example with max_leading_padding_zeroes_in_precision_mode = 6.
238 // ToPrecision(0.0000012345, 2) -> "0.0000012" 238 // ToPrecision(0.0000012345, 2) -> "0.0000012"
239 // ToPrecision(0.00000012345, 2) -> "1.2e-7" 239 // ToPrecision(0.00000012345, 2) -> "1.2e-7"
240 // Similarily the converter may add up to 240 // Similarily the converter may add up to
(...skipping 17 matching lines...) Expand all
258 // - the input value is special and no infinity_symbol or nan_symbol h as 258 // - the input value is special and no infinity_symbol or nan_symbol h as
259 // been provided to the constructor, 259 // been provided to the constructor,
260 // - precision < kMinPericisionDigits 260 // - precision < kMinPericisionDigits
261 // - precision > kMaxPrecisionDigits 261 // - precision > kMaxPrecisionDigits
262 // The last condition implies that the result will never contain more th an 262 // The last condition implies that the result will never contain more th an
263 // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the 263 // kMaxPrecisionDigits + 7 characters (the sign, the decimal point, the
264 // exponent character, the exponent's sign, and at most 3 exponent digit s). 264 // exponent character, the exponent's sign, and at most 3 exponent digit s).
265 bool ToPrecision(double value, 265 bool ToPrecision(double value,
266 int precision, 266 int precision,
267 StringBuilder* result_builder) const; 267 StringBuilder* result_builder) const;
268 268
269 enum DtoaMode { 269 enum DtoaMode {
270 // Produce the shortest correct representation. 270 // Produce the shortest correct representation.
271 // For example the output of 0.299999999999999988897 is (the less ac curate 271 // For example the output of 0.299999999999999988897 is (the less ac curate
272 // but correct) 0.3. 272 // but correct) 0.3.
273 SHORTEST, 273 SHORTEST,
274 // Produce a fixed number of digits after the decimal point. 274 // Produce a fixed number of digits after the decimal point.
275 // For instance fixed(0.1, 4) becomes 0.1000 275 // For instance fixed(0.1, 4) becomes 0.1000
276 // If the input number is big, the output will be big. 276 // If the input number is big, the output will be big.
277 FIXED, 277 FIXED,
278 // Fixed number of digits (independent of the decimal point). 278 // Fixed number of digits (independent of the decimal point).
279 PRECISION 279 PRECISION
280 }; 280 };
281 281
282 // The maximal number of digits that are needed to emit a double in base 10. 282 // The maximal number of digits that are needed to emit a double in base 10.
283 // A higher precision can be achieved by using more digits, but the shor test 283 // A higher precision can be achieved by using more digits, but the shor test
284 // accurate representation of any double will never use more digits than 284 // accurate representation of any double will never use more digits than
285 // kBase10MaximalLength. 285 // kBase10MaximalLength.
286 // Note that DoubleToAscii null-terminates its input. So the given buffe r 286 // Note that DoubleToAscii null-terminates its input. So the given buffe r
287 // should be at least kBase10MaximalLength + 1 characters long. 287 // should be at least kBase10MaximalLength + 1 characters long.
288 static const int kBase10MaximalLength = 17; 288 static const int kBase10MaximalLength = 17;
289 289
290 // Converts the given double 'v' to ascii. 290 // Converts the given double 'v' to ascii.
291 // The result should be interpreted as buffer * 10^(point-length). 291 // The result should be interpreted as buffer * 10^(point-length).
292 // 292 //
293 // The output depends on the given mode: 293 // The output depends on the given mode:
294 // - SHORTEST: produce the least amount of digits for which the interna l 294 // - SHORTEST: produce the least amount of digits for which the interna l
295 // identity requirement is still satisfied. If the digits are printed 295 // identity requirement is still satisfied. If the digits are printed
296 // (together with the correct exponent) then reading this number will give 296 // (together with the correct exponent) then reading this number will give
297 // 'v' again. The buffer will choose the representation that is closes t to 297 // 'v' again. The buffer will choose the representation that is closes t to
298 // 'v'. If there are two at the same distance, than the one farther aw ay 298 // 'v'. If there are two at the same distance, than the one farther aw ay
299 // from 0 is chosen (halfway cases - ending with 5 - are rounded up). 299 // from 0 is chosen (halfway cases - ending with 5 - are rounded up).
(...skipping 19 matching lines...) Expand all
319 // the output. The given length is only used in debug mode to ensure the 319 // the output. The given length is only used in debug mode to ensure the
320 // buffer is big enough. 320 // buffer is big enough.
321 static void DoubleToAscii(double v, 321 static void DoubleToAscii(double v,
322 DtoaMode mode, 322 DtoaMode mode,
323 int requested_digits, 323 int requested_digits,
324 char* buffer, 324 char* buffer,
325 int buffer_length, 325 int buffer_length,
326 bool* sign, 326 bool* sign,
327 int* length, 327 int* length,
328 int* point); 328 int* point);
329 329
330 private: 330 private:
331 // If the value is a special value (NaN or Infinity) constructs the 331 // If the value is a special value (NaN or Infinity) constructs the
332 // corresponding string using the configured infinity/nan-symbol. 332 // corresponding string using the configured infinity/nan-symbol.
333 // If either of them is NULL or the value is not special then the 333 // If either of them is NULL or the value is not special then the
334 // function returns false. 334 // function returns false.
335 bool HandleSpecialValues(double value, StringBuilder* result_builder) co nst; 335 bool HandleSpecialValues(double value, StringBuilder* result_builder) co nst;
336 // Constructs an exponential representation (i.e. 1.234e56). 336 // Constructs an exponential representation (i.e. 1.234e56).
337 // The given exponent assumes a decimal point after the first decimal di git. 337 // The given exponent assumes a decimal point after the first decimal di git.
338 void CreateExponentialRepresentation(const char* decimal_digits, 338 void CreateExponentialRepresentation(const char* decimal_digits,
339 int length, 339 int length,
340 int exponent, 340 int exponent,
341 StringBuilder* result_builder) cons t; 341 StringBuilder* result_builder) cons t;
342 // Creates a decimal representation (i.e 1234.5678). 342 // Creates a decimal representation (i.e 1234.5678).
343 void CreateDecimalRepresentation(const char* decimal_digits, 343 void CreateDecimalRepresentation(const char* decimal_digits,
344 int length, 344 int length,
345 int decimal_point, 345 int decimal_point,
346 int digits_after_point, 346 int digits_after_point,
347 StringBuilder* result_builder) const; 347 StringBuilder* result_builder) const;
348 348
349 const int flags_; 349 const int flags_;
350 const char* const infinity_symbol_; 350 const char* const infinity_symbol_;
351 const char* const nan_symbol_; 351 const char* const nan_symbol_;
352 const char exponent_character_; 352 const char exponent_character_;
353 const int decimal_in_shortest_low_; 353 const int decimal_in_shortest_low_;
354 const int decimal_in_shortest_high_; 354 const int decimal_in_shortest_high_;
355 const int max_leading_padding_zeroes_in_precision_mode_; 355 const int max_leading_padding_zeroes_in_precision_mode_;
356 const int max_trailing_padding_zeroes_in_precision_mode_; 356 const int max_trailing_padding_zeroes_in_precision_mode_;
357 357
358 DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter); 358 DISALLOW_IMPLICIT_CONSTRUCTORS(DoubleToStringConverter);
359 }; 359 };
360 360
361 361
362 class StringToDoubleConverter { 362 class StringToDoubleConverter {
363 public: 363 public:
364 // Performs the conversion. 364 // Performs the conversion.
365 // The output parameter 'processed_characters_count' is set to the numbe r 365 // The output parameter 'processed_characters_count' is set to the numbe r
366 // of characters that have been processed to read the number. 366 // of characters that have been processed to read the number.
367 static double StringToDouble(const char* buffer, size_t length, size_t* processed_characters_count); 367 static double StringToDouble(const char* buffer, size_t length, size_t* processed_characters_count);
368 368
369 private: 369 private:
370 DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter); 370 DISALLOW_IMPLICIT_CONSTRUCTORS(StringToDoubleConverter);
371 }; 371 };
372 372
373 } // namespace double_conversion 373 } // namespace double_conversion
374 374
375 } // namespace WTF 375 } // namespace WTF
376 376
377 #endif // DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_ 377 #endif // DOUBLE_CONVERSION_DOUBLE_CONVERSION_H_
OLDNEW
« no previous file with comments | « Source/wtf/dtoa/double.h ('k') | Source/wtf/dtoa/fast-dtoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698