| 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/double_conversion.h" | 10 #include "vm/double_conversion.h" | 
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 181   GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); | 181   GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); | 
| 182   double d = arg.value(); | 182   double d = arg.value(); | 
| 183   intptr_t fraction_digits_value = fraction_digits.Value(); | 183   intptr_t fraction_digits_value = fraction_digits.Value(); | 
| 184   if (0 <= fraction_digits_value && fraction_digits_value <= 20 | 184   if (0 <= fraction_digits_value && fraction_digits_value <= 20 | 
| 185       && kLowerBoundary < d && d < kUpperBoundary) { | 185       && kLowerBoundary < d && d < kUpperBoundary) { | 
| 186     return DoubleToStringAsFixed(d, static_cast<int>(fraction_digits_value)); | 186     return DoubleToStringAsFixed(d, static_cast<int>(fraction_digits_value)); | 
| 187   } else { | 187   } else { | 
| 188     GrowableArray<const Object*> args; | 188     GrowableArray<const Object*> args; | 
| 189     args.Add(&String::ZoneHandle(String::New( | 189     args.Add(&String::ZoneHandle(String::New( | 
| 190         "Illegal arguments to double.toStringAsFixed"))); | 190         "Illegal arguments to double.toStringAsFixed"))); | 
| 191     Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 191     Exceptions::ThrowByType(Exceptions::kArgument, args); | 
| 192     return Object::null(); | 192     return Object::null(); | 
| 193   } | 193   } | 
| 194 } | 194 } | 
| 195 | 195 | 
| 196 | 196 | 
| 197 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { | 197 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { | 
| 198   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 198   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 
| 199   GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); | 199   GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); | 
| 200   double d = arg.value(); | 200   double d = arg.value(); | 
| 201   intptr_t fraction_digits_value = fraction_digits.Value(); | 201   intptr_t fraction_digits_value = fraction_digits.Value(); | 
| 202   if (-1 <= fraction_digits_value && fraction_digits_value <= 20) { | 202   if (-1 <= fraction_digits_value && fraction_digits_value <= 20) { | 
| 203     return DoubleToStringAsExponential( | 203     return DoubleToStringAsExponential( | 
| 204         d, static_cast<int>(fraction_digits_value)); | 204         d, static_cast<int>(fraction_digits_value)); | 
| 205   } else { | 205   } else { | 
| 206     GrowableArray<const Object*> args; | 206     GrowableArray<const Object*> args; | 
| 207     args.Add(&String::ZoneHandle(String::New( | 207     args.Add(&String::ZoneHandle(String::New( | 
| 208         "Illegal arguments to double.toStringAsExponential"))); | 208         "Illegal arguments to double.toStringAsExponential"))); | 
| 209     Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 209     Exceptions::ThrowByType(Exceptions::kArgument, args); | 
| 210     return Object::null(); | 210     return Object::null(); | 
| 211   } | 211   } | 
| 212 } | 212 } | 
| 213 | 213 | 
| 214 | 214 | 
| 215 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { | 215 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { | 
| 216   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 216   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 
| 217   GET_NATIVE_ARGUMENT(Smi, precision, arguments->At(1)); | 217   GET_NATIVE_ARGUMENT(Smi, precision, arguments->At(1)); | 
| 218   double d = arg.value(); | 218   double d = arg.value(); | 
| 219   intptr_t precision_value = precision.Value(); | 219   intptr_t precision_value = precision.Value(); | 
| 220   if (1 <= precision_value && precision_value <= 21) { | 220   if (1 <= precision_value && precision_value <= 21) { | 
| 221     return DoubleToStringAsPrecision(d, static_cast<int>(precision_value)); | 221     return DoubleToStringAsPrecision(d, static_cast<int>(precision_value)); | 
| 222   } else { | 222   } else { | 
| 223     GrowableArray<const Object*> args; | 223     GrowableArray<const Object*> args; | 
| 224     args.Add(&String::ZoneHandle(String::New( | 224     args.Add(&String::ZoneHandle(String::New( | 
| 225         "Illegal arguments to double.toStringAsPrecision"))); | 225         "Illegal arguments to double.toStringAsPrecision"))); | 
| 226     Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); | 226     Exceptions::ThrowByType(Exceptions::kArgument, args); | 
| 227     return Object::null(); | 227     return Object::null(); | 
| 228   } | 228   } | 
| 229 } | 229 } | 
| 230 | 230 | 
| 231 | 231 | 
| 232 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { | 232 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { | 
| 233   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 233   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 
| 234   return Bool::Get(isinf(arg.value())); | 234   return Bool::Get(isinf(arg.value())); | 
| 235 } | 235 } | 
| 236 | 236 | 
| 237 | 237 | 
| 238 DEFINE_NATIVE_ENTRY(Double_isNaN, 1) { | 238 DEFINE_NATIVE_ENTRY(Double_isNaN, 1) { | 
| 239   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 239   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 
| 240   return Bool::Get(isnan(arg.value())); | 240   return Bool::Get(isnan(arg.value())); | 
| 241 } | 241 } | 
| 242 | 242 | 
| 243 | 243 | 
| 244 DEFINE_NATIVE_ENTRY(Double_isNegative, 1) { | 244 DEFINE_NATIVE_ENTRY(Double_isNegative, 1) { | 
| 245   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 245   const Double& arg = Double::CheckedHandle(arguments->At(0)); | 
| 246   // Include negative zero, infinity. | 246   // Include negative zero, infinity. | 
| 247   return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 247   return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 
| 248 } | 248 } | 
| 249 | 249 | 
| 250 // Add here only functions using/referring to old-style casts. | 250 // Add here only functions using/referring to old-style casts. | 
| 251 | 251 | 
| 252 }  // namespace dart | 252 }  // namespace dart | 
| OLD | NEW | 
|---|