OLD | NEW |
1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 646 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
657 | 657 |
658 // Get the integer part and the decimal part. | 658 // Get the integer part and the decimal part. |
659 double integer_part = floor(value); | 659 double integer_part = floor(value); |
660 double decimal_part = value - integer_part; | 660 double decimal_part = value - integer_part; |
661 | 661 |
662 // Convert the integer part starting from the back. Always generate | 662 // Convert the integer part starting from the back. Always generate |
663 // at least one digit. | 663 // at least one digit. |
664 int integer_pos = kBufferSize - 2; | 664 int integer_pos = kBufferSize - 2; |
665 do { | 665 do { |
666 integer_buffer[integer_pos--] = | 666 integer_buffer[integer_pos--] = |
667 chars[static_cast<int>(fmod(integer_part, radix))]; | 667 chars[static_cast<int>(modulo(integer_part, radix))]; |
668 integer_part /= radix; | 668 integer_part /= radix; |
669 } while (integer_part >= 1.0); | 669 } while (integer_part >= 1.0); |
670 // Sanity check. | 670 // Sanity check. |
671 ASSERT(integer_pos > 0); | 671 ASSERT(integer_pos > 0); |
672 // Add sign if needed. | 672 // Add sign if needed. |
673 if (is_negative) integer_buffer[integer_pos--] = '-'; | 673 if (is_negative) integer_buffer[integer_pos--] = '-'; |
674 | 674 |
675 // Convert the decimal part. Repeatedly multiply by the radix to | 675 // Convert the decimal part. Repeatedly multiply by the radix to |
676 // generate the next char. Never generate more than kBufferSize - 1 | 676 // generate the next char. Never generate more than kBufferSize - 1 |
677 // chars. | 677 // chars. |
(...skipping 21 matching lines...) Expand all Loading... |
699 // Allocate result and fill in the parts. | 699 // Allocate result and fill in the parts. |
700 StringBuilder builder(result_size + 1); | 700 StringBuilder builder(result_size + 1); |
701 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 701 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
702 if (decimal_pos > 0) builder.AddCharacter('.'); | 702 if (decimal_pos > 0) builder.AddCharacter('.'); |
703 builder.AddSubstring(decimal_buffer, decimal_pos); | 703 builder.AddSubstring(decimal_buffer, decimal_pos); |
704 return builder.Finalize(); | 704 return builder.Finalize(); |
705 } | 705 } |
706 | 706 |
707 | 707 |
708 } } // namespace v8::internal | 708 } } // namespace v8::internal |
OLD | NEW |