| OLD | NEW |
| 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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 static void FillFractionals(uint64_t fractionals, int exponent, | 233 static void FillFractionals(uint64_t fractionals, int exponent, |
| 234 int fractional_count, Vector<char> buffer, | 234 int fractional_count, Vector<char> buffer, |
| 235 int* length, int* decimal_point) { | 235 int* length, int* decimal_point) { |
| 236 DCHECK_LE(-128, exponent); | 236 DCHECK_LE(-128, exponent); |
| 237 DCHECK_LE(exponent, 0); | 237 DCHECK_LE(exponent, 0); |
| 238 // 'fractionals' is a fixed-point number, with binary point at bit | 238 // 'fractionals' is a fixed-point number, with binary point at bit |
| 239 // (-exponent). Inside the function the non-converted remainder of fract
ionals | 239 // (-exponent). Inside the function the non-converted remainder of fract
ionals |
| 240 // is a fixed-point number, with binary point at bit 'point'. | 240 // is a fixed-point number, with binary point at bit 'point'. |
| 241 if (-exponent <= 64) { | 241 if (-exponent <= 64) { |
| 242 // One 64 bit number is sufficient. | 242 // One 64 bit number is sufficient. |
| 243 DCHECK(fractionals >> 56 == 0); | 243 DCHECK_EQ(fractionals >> 56, 0UL); |
| 244 int point = -exponent; | 244 int point = -exponent; |
| 245 for (int i = 0; i < fractional_count; ++i) { | 245 for (int i = 0; i < fractional_count; ++i) { |
| 246 if (fractionals == 0) break; | 246 if (fractionals == 0) break; |
| 247 // Instead of multiplying by 10 we multiply by 5 and adjust the
point | 247 // Instead of multiplying by 10 we multiply by 5 and adjust the
point |
| 248 // location. This way the fractionals variable will not overflow
. | 248 // location. This way the fractionals variable will not overflow
. |
| 249 // Invariant at the beginning of the loop: fractionals < 2^point
. | 249 // Invariant at the beginning of the loop: fractionals < 2^point
. |
| 250 // Initially we have: point <= 64 and fractionals < 2^56 | 250 // Initially we have: point <= 64 and fractionals < 2^56 |
| 251 // After each iteration the point is decremented by one. | 251 // After each iteration the point is decremented by one. |
| 252 // Note that 5^3 = 125 < 128 = 2^7. | 252 // Note that 5^3 = 125 < 128 = 2^7. |
| 253 // Therefore three iterations of this loop will not overflow fra
ctionals | 253 // Therefore three iterations of this loop will not overflow fra
ctionals |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 400 // The string is empty and the decimal_point thus has no importance.
Mimick | 400 // The string is empty and the decimal_point thus has no importance.
Mimick |
| 401 // Gay's dtoa and and set it to -fractional_count. | 401 // Gay's dtoa and and set it to -fractional_count. |
| 402 *decimal_point = -fractional_count; | 402 *decimal_point = -fractional_count; |
| 403 } | 403 } |
| 404 return true; | 404 return true; |
| 405 } | 405 } |
| 406 | 406 |
| 407 } // namespace double_conversion | 407 } // namespace double_conversion |
| 408 | 408 |
| 409 } // namespace WTF | 409 } // namespace WTF |
| OLD | NEW |