| 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/exceptions.h" | 11 #include "vm/exceptions.h" |
| 11 #include "vm/native_entry.h" | 12 #include "vm/native_entry.h" |
| 12 #include "vm/object.h" | 13 #include "vm/object.h" |
| 13 | 14 |
| 14 namespace dart { | 15 namespace dart { |
| 15 | 16 |
| 16 DEFINE_NATIVE_ENTRY(Double_doubleFromInteger, 2) { | 17 DEFINE_NATIVE_ENTRY(Double_doubleFromInteger, 2) { |
| 17 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); | 18 ASSERT(AbstractTypeArguments::CheckedHandle(arguments->At(0)).IsNull()); |
| 18 const Integer& value = Integer::CheckedHandle(arguments->At(1)); | 19 const Integer& value = Integer::CheckedHandle(arguments->At(1)); |
| 19 const Double& result = Double::Handle(Double::New(value.AsDoubleValue())); | 20 const Double& result = Double::Handle(Double::New(value.AsDoubleValue())); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 arguments->SetReturn(Smi::Handle(Smi::New(static_cast<intptr_t>(result)))); | 178 arguments->SetReturn(Smi::Handle(Smi::New(static_cast<intptr_t>(result)))); |
| 178 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) { | 179 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) { |
| 179 arguments->SetReturn(Mint::Handle(Mint::New(static_cast<int64_t>(result)))); | 180 arguments->SetReturn(Mint::Handle(Mint::New(static_cast<int64_t>(result)))); |
| 180 } else { | 181 } else { |
| 181 arguments->SetReturn( | 182 arguments->SetReturn( |
| 182 Bigint::Handle(BigintOperations::NewFromDouble(result))); | 183 Bigint::Handle(BigintOperations::NewFromDouble(result))); |
| 183 } | 184 } |
| 184 } | 185 } |
| 185 | 186 |
| 186 | 187 |
| 188 DEFINE_NATIVE_ENTRY(Double_toStringAsFixed, 2) { |
| 189 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
| 190 GET_NATIVE_ARGUMENT(Smi, fraction_digits, arguments->At(1)); |
| 191 double d = arg.value(); |
| 192 int fraction_digits_value = fraction_digits.Value(); |
| 193 String& result = String::Handle(); |
| 194 bool succeeded = DoubleToStringAsFixed(d, fraction_digits_value, result); |
| 195 if (!succeeded) { |
| 196 GrowableArray<const Object*> args; |
| 197 args.Add(&String::ZoneHandle(String::New( |
| 198 "Illegal arguments to double.toStringAsFixed"))); |
| 199 Exceptions::ThrowByType(Exceptions::kIllegalArgument, args); |
| 200 } |
| 201 arguments->SetReturn(result); |
| 202 } |
| 203 |
| 204 |
| 205 DEFINE_NATIVE_ENTRY(Double_toStringAsExponential, 2) { |
| 206 UNIMPLEMENTED(); |
| 207 } |
| 208 |
| 209 |
| 210 DEFINE_NATIVE_ENTRY(Double_toStringAsPrecision, 2) { |
| 211 UNIMPLEMENTED(); |
| 212 } |
| 213 |
| 214 |
| 187 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { | 215 DEFINE_NATIVE_ENTRY(Double_isInfinite, 1) { |
| 188 const Double& arg = Double::CheckedHandle(arguments->At(0)); | 216 const Double& arg = Double::CheckedHandle(arguments->At(0)); |
| 189 if (isinf(arg.value())) { | 217 if (isinf(arg.value())) { |
| 190 arguments->SetReturn(Bool::Handle(Bool::True())); | 218 arguments->SetReturn(Bool::Handle(Bool::True())); |
| 191 } else { | 219 } else { |
| 192 arguments->SetReturn(Bool::Handle(Bool::False())); | 220 arguments->SetReturn(Bool::Handle(Bool::False())); |
| 193 } | 221 } |
| 194 } | 222 } |
| 195 | 223 |
| 196 | 224 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 211 arguments->SetReturn(Bool::Handle(Bool::True())); | 239 arguments->SetReturn(Bool::Handle(Bool::True())); |
| 212 } else { | 240 } else { |
| 213 arguments->SetReturn(Bool::Handle(Bool::False())); | 241 arguments->SetReturn(Bool::Handle(Bool::False())); |
| 214 } | 242 } |
| 215 } | 243 } |
| 216 | 244 |
| 217 // Add here only functions using/referring to old-style casts. | 245 // Add here only functions using/referring to old-style casts. |
| 218 | 246 |
| 219 } // namespace dart | 247 } // namespace dart |
| 220 | 248 |
| OLD | NEW |