| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 if (is_negative) value = -value; | 394 if (is_negative) value = -value; |
| 395 | 395 |
| 396 // Get the integer part and the decimal part. | 396 // Get the integer part and the decimal part. |
| 397 double integer_part = floor(value); | 397 double integer_part = floor(value); |
| 398 double decimal_part = value - integer_part; | 398 double decimal_part = value - integer_part; |
| 399 | 399 |
| 400 // Convert the integer part starting from the back. Always generate | 400 // Convert the integer part starting from the back. Always generate |
| 401 // at least one digit. | 401 // at least one digit. |
| 402 int integer_pos = kBufferSize - 2; | 402 int integer_pos = kBufferSize - 2; |
| 403 do { | 403 do { |
| 404 integer_buffer[integer_pos--] = | 404 double remainder = fmod(integer_part, radix); |
| 405 chars[static_cast<int>(fmod(integer_part, radix))]; | 405 integer_buffer[integer_pos--] = chars[static_cast<int>(remainder)]; |
| 406 integer_part -= remainder; |
| 406 integer_part /= radix; | 407 integer_part /= radix; |
| 407 } while (integer_part >= 1.0); | 408 } while (integer_part >= 1.0); |
| 408 // Sanity check. | 409 // Sanity check. |
| 409 ASSERT(integer_pos > 0); | 410 ASSERT(integer_pos > 0); |
| 410 // Add sign if needed. | 411 // Add sign if needed. |
| 411 if (is_negative) integer_buffer[integer_pos--] = '-'; | 412 if (is_negative) integer_buffer[integer_pos--] = '-'; |
| 412 | 413 |
| 413 // Convert the decimal part. Repeatedly multiply by the radix to | 414 // Convert the decimal part. Repeatedly multiply by the radix to |
| 414 // generate the next char. Never generate more than kBufferSize - 1 | 415 // generate the next char. Never generate more than kBufferSize - 1 |
| 415 // chars. | 416 // chars. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 436 if (decimal_pos > 0) result_size++; | 437 if (decimal_pos > 0) result_size++; |
| 437 // Allocate result and fill in the parts. | 438 // Allocate result and fill in the parts. |
| 438 SimpleStringBuilder builder(result_size + 1); | 439 SimpleStringBuilder builder(result_size + 1); |
| 439 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); | 440 builder.AddSubstring(integer_buffer + integer_pos + 1, integer_part_size); |
| 440 if (decimal_pos > 0) builder.AddCharacter('.'); | 441 if (decimal_pos > 0) builder.AddCharacter('.'); |
| 441 builder.AddSubstring(decimal_buffer, decimal_pos); | 442 builder.AddSubstring(decimal_buffer, decimal_pos); |
| 442 return builder.Finalize(); | 443 return builder.Finalize(); |
| 443 } | 444 } |
| 444 | 445 |
| 445 } } // namespace v8::internal | 446 } } // namespace v8::internal |
| OLD | NEW |