| 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 14 matching lines...) Expand all Loading... |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 #ifndef V8_DTOA_H_ | 28 #ifndef V8_DTOA_H_ |
| 29 #define V8_DTOA_H_ | 29 #define V8_DTOA_H_ |
| 30 | 30 |
| 31 namespace v8 { | 31 namespace v8 { |
| 32 namespace internal { | 32 namespace internal { |
| 33 | 33 |
| 34 enum DtoaMode { | 34 enum DtoaMode { |
| 35 // 0.9999999999999999 becomes 0.1 | 35 // Return the shortest correct representation. |
| 36 // For example the output of 0.299999999999999988897 is (the less accurate but |
| 37 // correct) 0.3. |
| 36 DTOA_SHORTEST, | 38 DTOA_SHORTEST, |
| 37 // Fixed number of digits after the decimal point. | 39 // Return a fixed number of digits after the decimal point. |
| 38 // For instance fixed(0.1, 4) becomes 0.1000 | 40 // For instance fixed(0.1, 4) becomes 0.1000 |
| 39 // If the input number is big, the output will be big. | 41 // If the input number is big, the output will be big. |
| 40 DTOA_FIXED, | 42 DTOA_FIXED, |
| 41 // Fixed number of digits (independent of the decimal point). | 43 // Return a fixed number of digits, no matter what the exponent is. |
| 42 DTOA_PRECISION | 44 DTOA_PRECISION |
| 43 }; | 45 }; |
| 44 | 46 |
| 45 // The maximal length of digits a double can have in base 10. | 47 // The maximal length of digits a double can have in base 10. |
| 46 // Note that DoubleToAscii null-terminates its input. So the given buffer should | 48 // Note that DoubleToAscii null-terminates its input. So the given buffer should |
| 47 // be at least kBase10MaximalLength + 1 characters long. | 49 // be at least kBase10MaximalLength + 1 characters long. |
| 48 static const int kBase10MaximalLength = 17; | 50 static const int kBase10MaximalLength = 17; |
| 49 | 51 |
| 50 // Converts the given double 'v' to ascii. | 52 // Converts the given double 'v' to ascii. |
| 51 // The result should be interpreted as buffer * 10^(point-length). | 53 // The result should be interpreted as buffer * 10^(point-length). |
| (...skipping 13 matching lines...) Expand all Loading... |
| 65 // Halfway cases are rounded towards +/-Infinity (away from 0). The call | 67 // Halfway cases are rounded towards +/-Infinity (away from 0). The call |
| 66 // toFixed(0.15, 2) thus returns buffer="2", point=0. | 68 // toFixed(0.15, 2) thus returns buffer="2", point=0. |
| 67 // The returned buffer may contain digits that would be truncated from the | 69 // The returned buffer may contain digits that would be truncated from the |
| 68 // shortest representation of the input. | 70 // shortest representation of the input. |
| 69 // - PRECISION: produces 'requested_digits' where the first digit is not '0'. | 71 // - PRECISION: produces 'requested_digits' where the first digit is not '0'. |
| 70 // Even though the length of produced digits usually equals | 72 // Even though the length of produced digits usually equals |
| 71 // 'requested_digits', the function is allowed to return fewer digits, in | 73 // 'requested_digits', the function is allowed to return fewer digits, in |
| 72 // which case the caller has to fill the missing digits with '0's. | 74 // which case the caller has to fill the missing digits with '0's. |
| 73 // Halfway cases are again rounded away from 0. | 75 // Halfway cases are again rounded away from 0. |
| 74 // 'DoubleToAscii' expects the given buffer to be big enough to hold all digits | 76 // 'DoubleToAscii' expects the given buffer to be big enough to hold all digits |
| 75 // and a terminating null-character. | 77 // and a terminating null-character. In SHORTEST-mode it expects a buffer of |
| 76 bool DoubleToAscii(double v, DtoaMode mode, int requested_digits, | 78 // at least kBase10MaximalLength + 1. Otherwise, the size of the output is |
| 79 // limited to requested_digits digits plus the null terminator. |
| 80 void DoubleToAscii(double v, DtoaMode mode, int requested_digits, |
| 77 Vector<char> buffer, int* sign, int* length, int* point); | 81 Vector<char> buffer, int* sign, int* length, int* point); |
| 78 | 82 |
| 79 } } // namespace v8::internal | 83 } } // namespace v8::internal |
| 80 | 84 |
| 81 #endif // V8_DTOA_H_ | 85 #endif // V8_DTOA_H_ |
| OLD | NEW |