OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include <math.h> | 5 #include <math.h> |
6 | 6 |
7 #include "vm/bootstrap_natives.h" | 7 #include "vm/bootstrap_natives.h" |
8 | 8 |
9 #include "vm/bigint_operations.h" | 9 #include "vm/bigint_operations.h" |
10 #include "vm/code_generator.h" // DartModulo. | 10 #include "vm/code_generator.h" // DartModulo. |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 #endif | 193 #endif |
194 | 194 |
195 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { | 195 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { |
196 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 196 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
197 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); | 197 return DoubleToInteger(arg.value(), "Infinity or NaN toInt"); |
198 } | 198 } |
199 | 199 |
200 | 200 |
201 DEFINE_NATIVE_ENTRY(Double_parse, 1) { | 201 DEFINE_NATIVE_ENTRY(Double_parse, 1) { |
202 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); | 202 GET_NON_NULL_NATIVE_ARGUMENT(String, value, arguments->NativeArgAt(0)); |
| 203 if (value.IsOneByteString()) { |
| 204 // Quick conversion for unpadded doubles in strings. |
| 205 const intptr_t len = value.Length(); |
| 206 if (len > 0) { |
| 207 const char* cstr = value.ToCString(); |
| 208 ASSERT(cstr != NULL); |
| 209 // Dart differences from strtod: |
| 210 // a) '5.' is not a valid double (no digit after period). |
| 211 // b) '+5.0' is not a valid double (leading plus). |
| 212 if (cstr[0] != '+') { |
| 213 bool dot_ok = true; |
| 214 const char* tmp = cstr; |
| 215 while (*tmp != '\0') { |
| 216 const char ch = *tmp++; |
| 217 if (ch == '.') { |
| 218 const char nextCh = *tmp; |
| 219 dot_ok = ('0' <= nextCh) && (nextCh <= '9'); |
| 220 break; |
| 221 } |
| 222 } |
| 223 if (dot_ok) { |
| 224 char* p_end = NULL; |
| 225 const double double_value = strtod(cstr, &p_end); |
| 226 if (p_end == (cstr + len)) { |
| 227 return Double::New(double_value); |
| 228 } |
| 229 } |
| 230 } |
| 231 } |
| 232 } |
203 Scanner scanner(value, Symbols::Empty()); | 233 Scanner scanner(value, Symbols::Empty()); |
204 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); | 234 const Scanner::GrowableTokenStream& tokens = scanner.GetStream(); |
205 String* number_string; | 235 String* number_string; |
206 bool is_positive; | 236 bool is_positive; |
207 if (Scanner::IsValidLiteral(tokens, | 237 if (Scanner::IsValidLiteral(tokens, |
208 Token::kDOUBLE, | 238 Token::kDOUBLE, |
209 &is_positive, | 239 &is_positive, |
210 &number_string)) { | 240 &number_string)) { |
211 const char* cstr = number_string->ToCString(); | 241 const char* cstr = number_string->ToCString(); |
212 char* p_end = NULL; | 242 char* p_end = NULL; |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 353 |
324 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 354 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
325 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 355 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
326 // Include negative zero, infinity. | 356 // Include negative zero, infinity. |
327 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 357 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
328 } | 358 } |
329 | 359 |
330 // Add here only functions using/referring to old-style casts. | 360 // Add here only functions using/referring to old-style casts. |
331 | 361 |
332 } // namespace dart | 362 } // namespace dart |
OLD | NEW |