OLD | NEW |
1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/conversions.h" | 5 #include "src/conversions.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 #include <stdarg.h> | 8 #include <stdarg.h> |
9 #include <cmath> | 9 #include <cmath> |
10 | 10 |
(...skipping 456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
467 buffer[fraction_cursor++] = chars[digit + 1]; | 467 buffer[fraction_cursor++] = chars[digit + 1]; |
468 break; | 468 break; |
469 } | 469 } |
470 } | 470 } |
471 break; | 471 break; |
472 } | 472 } |
473 } | 473 } |
474 } while (fraction > delta); | 474 } while (fraction > delta); |
475 } | 475 } |
476 | 476 |
477 // Compute integer digits. | 477 // Compute integer digits. Fill unrepresented digits with zero. |
| 478 while (Double(integer / radix).Exponent() > 0) { |
| 479 integer /= radix; |
| 480 buffer[--integer_cursor] = '0'; |
| 481 } |
478 do { | 482 do { |
479 double multiple = std::floor(integer / radix); | 483 double remainder = modulo(integer, radix); |
480 int digit = static_cast<int>(integer - multiple * radix); | 484 buffer[--integer_cursor] = chars[static_cast<int>(remainder)]; |
481 buffer[--integer_cursor] = chars[digit]; | 485 integer = (integer - remainder) / radix; |
482 integer = multiple; | |
483 } while (integer > 0); | 486 } while (integer > 0); |
484 | 487 |
485 // Add sign and terminate string. | 488 // Add sign and terminate string. |
486 if (negative) buffer[--integer_cursor] = '-'; | 489 if (negative) buffer[--integer_cursor] = '-'; |
487 buffer[fraction_cursor++] = '\0'; | 490 buffer[fraction_cursor++] = '\0'; |
488 // Allocate new string as return value. | 491 // Allocate new string as return value. |
489 char* result = NewArray<char>(fraction_cursor - integer_cursor); | 492 char* result = NewArray<char>(fraction_cursor - integer_cursor); |
490 memcpy(result, buffer + integer_cursor, fraction_cursor - integer_cursor); | 493 memcpy(result, buffer + integer_cursor, fraction_cursor - integer_cursor); |
491 return result; | 494 return result; |
492 } | 495 } |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
563 char reverse_buffer[kBufferSize + 1]; // Result will be /0 terminated. | 566 char reverse_buffer[kBufferSize + 1]; // Result will be /0 terminated. |
564 Vector<char> reverse_vector(reverse_buffer, arraysize(reverse_buffer)); | 567 Vector<char> reverse_vector(reverse_buffer, arraysize(reverse_buffer)); |
565 const char* reverse_string = DoubleToCString(d, reverse_vector); | 568 const char* reverse_string = DoubleToCString(d, reverse_vector); |
566 for (int i = 0; i < length; ++i) { | 569 for (int i = 0; i < length; ++i) { |
567 if (static_cast<uint16_t>(reverse_string[i]) != buffer[i]) return false; | 570 if (static_cast<uint16_t>(reverse_string[i]) != buffer[i]) return false; |
568 } | 571 } |
569 return true; | 572 return true; |
570 } | 573 } |
571 } // namespace internal | 574 } // namespace internal |
572 } // namespace v8 | 575 } // namespace v8 |
OLD | NEW |