| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 uint32_t part = static_cast<uint32_t>(accumulator & kMask32); | 48 uint32_t part = static_cast<uint32_t>(accumulator & kMask32); |
| 49 accumulator >>= 32; | 49 accumulator >>= 32; |
| 50 accumulator = accumulator + (low_bits_ >> 32) * multiplicand; | 50 accumulator = accumulator + (low_bits_ >> 32) * multiplicand; |
| 51 low_bits_ = (accumulator << 32) + part; | 51 low_bits_ = (accumulator << 32) + part; |
| 52 accumulator >>= 32; | 52 accumulator >>= 32; |
| 53 accumulator = accumulator + (high_bits_ & kMask32) * multiplicand; | 53 accumulator = accumulator + (high_bits_ & kMask32) * multiplicand; |
| 54 part = static_cast<uint32_t>(accumulator & kMask32); | 54 part = static_cast<uint32_t>(accumulator & kMask32); |
| 55 accumulator >>= 32; | 55 accumulator >>= 32; |
| 56 accumulator = accumulator + (high_bits_ >> 32) * multiplicand; | 56 accumulator = accumulator + (high_bits_ >> 32) * multiplicand; |
| 57 high_bits_ = (accumulator << 32) + part; | 57 high_bits_ = (accumulator << 32) + part; |
| 58 ASSERT((accumulator >> 32) == 0); | 58 DCHECK_EQ((accumulator >> 32), 0u); |
| 59 } | 59 } |
| 60 | 60 |
| 61 void Shift(int shift_amount) { | 61 void Shift(int shift_amount) { |
| 62 ASSERT(-64 <= shift_amount && shift_amount <= 64); | 62 DCHECK_LE(-64, shift_amount); |
| 63 DCHECK_LE(shift_amount, 64); |
| 63 if (shift_amount == 0) { | 64 if (shift_amount == 0) { |
| 64 return; | 65 return; |
| 65 } else if (shift_amount == -64) { | 66 } else if (shift_amount == -64) { |
| 66 high_bits_ = low_bits_; | 67 high_bits_ = low_bits_; |
| 67 low_bits_ = 0; | 68 low_bits_ = 0; |
| 68 } else if (shift_amount == 64) { | 69 } else if (shift_amount == 64) { |
| 69 low_bits_ = high_bits_; | 70 low_bits_ = high_bits_; |
| 70 high_bits_ = 0; | 71 high_bits_ = 0; |
| 71 } else if (shift_amount <= 0) { | 72 } else if (shift_amount <= 0) { |
| 72 high_bits_ <<= -shift_amount; | 73 high_bits_ <<= -shift_amount; |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 // 0 <= fractionals * 2^exponent < 1 | 226 // 0 <= fractionals * 2^exponent < 1 |
| 226 // The buffer holds the result. | 227 // The buffer holds the result. |
| 227 // The function will round its result. During the rounding-process digits no
t | 228 // The function will round its result. During the rounding-process digits no
t |
| 228 // generated by this function might be updated, and the decimal-point variab
le | 229 // generated by this function might be updated, and the decimal-point variab
le |
| 229 // might be updated. If this function generates the digits 99 and the buffer | 230 // might be updated. If this function generates the digits 99 and the buffer |
| 230 // already contained "199" (thus yielding a buffer of "19999") then a | 231 // already contained "199" (thus yielding a buffer of "19999") then a |
| 231 // rounding-up will change the contents of the buffer to "20000". | 232 // rounding-up will change the contents of the buffer to "20000". |
| 232 static void FillFractionals(uint64_t fractionals, int exponent, | 233 static void FillFractionals(uint64_t fractionals, int exponent, |
| 233 int fractional_count, Vector<char> buffer, | 234 int fractional_count, Vector<char> buffer, |
| 234 int* length, int* decimal_point) { | 235 int* length, int* decimal_point) { |
| 235 ASSERT(-128 <= exponent && exponent <= 0); | 236 DCHECK_LE(-128, exponent); |
| 237 DCHECK_LE(exponent, 0); |
| 236 // 'fractionals' is a fixed-point number, with binary point at bit | 238 // 'fractionals' is a fixed-point number, with binary point at bit |
| 237 // (-exponent). Inside the function the non-converted remainder of fract
ionals | 239 // (-exponent). Inside the function the non-converted remainder of fract
ionals |
| 238 // is a fixed-point number, with binary point at bit 'point'. | 240 // is a fixed-point number, with binary point at bit 'point'. |
| 239 if (-exponent <= 64) { | 241 if (-exponent <= 64) { |
| 240 // One 64 bit number is sufficient. | 242 // One 64 bit number is sufficient. |
| 241 ASSERT(fractionals >> 56 == 0); | 243 ASSERT(fractionals >> 56 == 0); |
| 242 int point = -exponent; | 244 int point = -exponent; |
| 243 for (int i = 0; i < fractional_count; ++i) { | 245 for (int i = 0; i < fractional_count; ++i) { |
| 244 if (fractionals == 0) break; | 246 if (fractionals == 0) break; |
| 245 // 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 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 257 char digit = static_cast<char>(fractionals >> point); | 259 char digit = static_cast<char>(fractionals >> point); |
| 258 buffer[*length] = '0' + digit; | 260 buffer[*length] = '0' + digit; |
| 259 (*length)++; | 261 (*length)++; |
| 260 fractionals -= static_cast<uint64_t>(digit) << point; | 262 fractionals -= static_cast<uint64_t>(digit) << point; |
| 261 } | 263 } |
| 262 // If the first bit after the point is set we have to round up. | 264 // If the first bit after the point is set we have to round up. |
| 263 if (((fractionals >> (point - 1)) & 1) == 1) { | 265 if (((fractionals >> (point - 1)) & 1) == 1) { |
| 264 RoundUp(buffer, length, decimal_point); | 266 RoundUp(buffer, length, decimal_point); |
| 265 } | 267 } |
| 266 } else { // We need 128 bits. | 268 } else { // We need 128 bits. |
| 267 ASSERT(64 < -exponent && -exponent <= 128); | 269 DCHECK_LT(64, -exponent); |
| 270 DCHECK_LE(-exponent, 128); |
| 268 UInt128 fractionals128 = UInt128(fractionals, 0); | 271 UInt128 fractionals128 = UInt128(fractionals, 0); |
| 269 fractionals128.Shift(-exponent - 64); | 272 fractionals128.Shift(-exponent - 64); |
| 270 int point = 128; | 273 int point = 128; |
| 271 for (int i = 0; i < fractional_count; ++i) { | 274 for (int i = 0; i < fractional_count; ++i) { |
| 272 if (fractionals128.IsZero()) break; | 275 if (fractionals128.IsZero()) break; |
| 273 // As before: instead of multiplying by 10 we multiply by 5 and
adjust the | 276 // As before: instead of multiplying by 10 we multiply by 5 and
adjust the |
| 274 // point location. | 277 // point location. |
| 275 // This multiplication will not overflow for the same reasons as
before. | 278 // This multiplication will not overflow for the same reasons as
before. |
| 276 fractionals128.Multiply(5); | 279 fractionals128.Multiply(5); |
| 277 point--; | 280 point--; |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 375 FillDigits64(integrals, buffer, length); | 378 FillDigits64(integrals, buffer, length); |
| 376 } else { | 379 } else { |
| 377 FillDigits32(static_cast<uint32_t>(integrals), buffer, length); | 380 FillDigits32(static_cast<uint32_t>(integrals), buffer, length); |
| 378 } | 381 } |
| 379 *decimal_point = *length; | 382 *decimal_point = *length; |
| 380 FillFractionals(fractionals, exponent, fractional_count, | 383 FillFractionals(fractionals, exponent, fractional_count, |
| 381 buffer, length, decimal_point); | 384 buffer, length, decimal_point); |
| 382 } else if (exponent < -128) { | 385 } else if (exponent < -128) { |
| 383 // This configuration (with at most 20 digits) means that all digits
must be | 386 // This configuration (with at most 20 digits) means that all digits
must be |
| 384 // 0. | 387 // 0. |
| 385 ASSERT(fractional_count <= 20); | 388 DCHECK_LE(fractional_count, 20); |
| 386 buffer[0] = '\0'; | 389 buffer[0] = '\0'; |
| 387 *length = 0; | 390 *length = 0; |
| 388 *decimal_point = -fractional_count; | 391 *decimal_point = -fractional_count; |
| 389 } else { | 392 } else { |
| 390 *decimal_point = 0; | 393 *decimal_point = 0; |
| 391 FillFractionals(significand, exponent, fractional_count, | 394 FillFractionals(significand, exponent, fractional_count, |
| 392 buffer, length, decimal_point); | 395 buffer, length, decimal_point); |
| 393 } | 396 } |
| 394 TrimZeros(buffer, length, decimal_point); | 397 TrimZeros(buffer, length, decimal_point); |
| 395 buffer[*length] = '\0'; | 398 buffer[*length] = '\0'; |
| 396 if ((*length) == 0) { | 399 if ((*length) == 0) { |
| 397 // 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 |
| 398 // Gay's dtoa and and set it to -fractional_count. | 401 // Gay's dtoa and and set it to -fractional_count. |
| 399 *decimal_point = -fractional_count; | 402 *decimal_point = -fractional_count; |
| 400 } | 403 } |
| 401 return true; | 404 return true; |
| 402 } | 405 } |
| 403 | 406 |
| 404 } // namespace double_conversion | 407 } // namespace double_conversion |
| 405 | 408 |
| 406 } // namespace WTF | 409 } // namespace WTF |
| OLD | NEW |