| 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 34 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 45 const int kMaxSignificantDigits = 772; | 45 const int kMaxSignificantDigits = 772; | 
| 46 | 46 | 
| 47 | 47 | 
| 48 inline bool isDigit(int x, int radix) { | 48 inline bool isDigit(int x, int radix) { | 
| 49   return (x >= '0' && x <= '9' && x < '0' + radix) | 49   return (x >= '0' && x <= '9' && x < '0' + radix) | 
| 50       || (radix > 10 && x >= 'a' && x < 'a' + radix - 10) | 50       || (radix > 10 && x >= 'a' && x < 'a' + radix - 10) | 
| 51       || (radix > 10 && x >= 'A' && x < 'A' + radix - 10); | 51       || (radix > 10 && x >= 'A' && x < 'A' + radix - 10); | 
| 52 } | 52 } | 
| 53 | 53 | 
| 54 | 54 | 
|  | 55 inline bool isBinaryDigit(int x) { | 
|  | 56   return x == '0' || x == '1'; | 
|  | 57 } | 
|  | 58 | 
|  | 59 | 
| 55 // The fast double-to-(unsigned-)int conversion routine does not guarantee | 60 // The fast double-to-(unsigned-)int conversion routine does not guarantee | 
| 56 // rounding towards zero. | 61 // rounding towards zero. | 
| 57 // For NaN and values outside the int range, return INT_MIN or INT_MAX. | 62 // For NaN and values outside the int range, return INT_MIN or INT_MAX. | 
| 58 inline int FastD2IChecked(double x) { | 63 inline int FastD2IChecked(double x) { | 
| 59   if (!(x >= INT_MIN)) return INT_MIN;  // Negation to catch NaNs. | 64   if (!(x >= INT_MIN)) return INT_MIN;  // Negation to catch NaNs. | 
| 60   if (x > INT_MAX) return INT_MAX; | 65   if (x > INT_MAX) return INT_MAX; | 
| 61   return static_cast<int>(x); | 66   return static_cast<int>(x); | 
| 62 } | 67 } | 
| 63 | 68 | 
| 64 | 69 | 
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 101 inline uint32_t DoubleToUint32(double x) { | 106 inline uint32_t DoubleToUint32(double x) { | 
| 102   return static_cast<uint32_t>(DoubleToInt32(x)); | 107   return static_cast<uint32_t>(DoubleToInt32(x)); | 
| 103 } | 108 } | 
| 104 | 109 | 
| 105 | 110 | 
| 106 // Enumeration for allowing octals and ignoring junk when converting | 111 // Enumeration for allowing octals and ignoring junk when converting | 
| 107 // strings to numbers. | 112 // strings to numbers. | 
| 108 enum ConversionFlags { | 113 enum ConversionFlags { | 
| 109   NO_FLAGS = 0, | 114   NO_FLAGS = 0, | 
| 110   ALLOW_HEX = 1, | 115   ALLOW_HEX = 1, | 
| 111   ALLOW_OCTALS = 2, | 116   ALLOW_OCTAL = 2, | 
| 112   ALLOW_TRAILING_JUNK = 4 | 117   ALLOW_IMPLICIT_OCTAL = 4, | 
|  | 118   ALLOW_BINARY = 8, | 
|  | 119   ALLOW_TRAILING_JUNK = 16 | 
| 113 }; | 120 }; | 
| 114 | 121 | 
| 115 | 122 | 
| 116 // Converts a string into a double value according to ECMA-262 9.3.1 | 123 // Converts a string into a double value according to ECMA-262 9.3.1 | 
| 117 double StringToDouble(UnicodeCache* unicode_cache, | 124 double StringToDouble(UnicodeCache* unicode_cache, | 
| 118                       Vector<const char> str, | 125                       Vector<const char> str, | 
| 119                       int flags, | 126                       int flags, | 
| 120                       double empty_string_val = 0); | 127                       double empty_string_val = 0); | 
| 121 double StringToDouble(UnicodeCache* unicode_cache, | 128 double StringToDouble(UnicodeCache* unicode_cache, | 
| 122                       Vector<const uc16> str, | 129                       Vector<const uc16> str, | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
| 142 // Additional number to string conversions for the number type. | 149 // Additional number to string conversions for the number type. | 
| 143 // The caller is responsible for calling free on the returned pointer. | 150 // The caller is responsible for calling free on the returned pointer. | 
| 144 char* DoubleToFixedCString(double value, int f); | 151 char* DoubleToFixedCString(double value, int f); | 
| 145 char* DoubleToExponentialCString(double value, int f); | 152 char* DoubleToExponentialCString(double value, int f); | 
| 146 char* DoubleToPrecisionCString(double value, int f); | 153 char* DoubleToPrecisionCString(double value, int f); | 
| 147 char* DoubleToRadixCString(double value, int radix); | 154 char* DoubleToRadixCString(double value, int radix); | 
| 148 | 155 | 
| 149 } }  // namespace v8::internal | 156 } }  // namespace v8::internal | 
| 150 | 157 | 
| 151 #endif  // V8_CONVERSIONS_H_ | 158 #endif  // V8_CONVERSIONS_H_ | 
| OLD | NEW | 
|---|