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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 } | 72 } |
73 | 73 |
74 | 74 |
75 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { | 75 DEFINE_NATIVE_ENTRY(Double_trunc_div, 2) { |
76 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 76 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
77 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 77 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
78 double right = right_object.value(); | 78 double right = right_object.value(); |
79 if (FLAG_trace_intrinsified_natives) { | 79 if (FLAG_trace_intrinsified_natives) { |
80 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); | 80 OS::Print("Double_trunc_div %f ~/ %f\n", left, right); |
81 } | 81 } |
82 return Double::New(trunc(left / right)); | 82 double result = trunc(left / right); |
| 83 if (isinf(result) || isnan(result)) { |
| 84 const Array& args = Array::Handle(Array::New(1)); |
| 85 args.SetAt(0, String::Handle(String::New( |
| 86 "Result of truncating division is Infinity or NaN"))); |
| 87 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
| 88 } |
| 89 if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) { |
| 90 return Smi::New(static_cast<intptr_t>(result)); |
| 91 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) { |
| 92 return Mint::New(static_cast<int64_t>(result)); |
| 93 } else { |
| 94 return BigintOperations::NewFromDouble(result); |
| 95 } |
83 } | 96 } |
84 | 97 |
85 | 98 |
86 DEFINE_NATIVE_ENTRY(Double_modulo, 2) { | 99 DEFINE_NATIVE_ENTRY(Double_modulo, 2) { |
87 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 100 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
88 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 101 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
89 double right = right_object.value(); | 102 double right = right_object.value(); |
90 | 103 |
91 double remainder = fmod_ieee(left, right); | 104 double remainder = fmod_ieee(left, right); |
92 if (remainder == 0.0) { | 105 if (remainder == 0.0) { |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 #if defined(TARGET_OS_MACOS) | 197 #if defined(TARGET_OS_MACOS) |
185 // MAC OSX math library produces old style cast warning. | 198 // MAC OSX math library produces old style cast warning. |
186 #pragma GCC diagnostic ignored "-Wold-style-cast" | 199 #pragma GCC diagnostic ignored "-Wold-style-cast" |
187 #endif | 200 #endif |
188 | 201 |
189 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { | 202 DEFINE_NATIVE_ENTRY(Double_toInt, 1) { |
190 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 203 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
191 if (isinf(arg.value()) || isnan(arg.value())) { | 204 if (isinf(arg.value()) || isnan(arg.value())) { |
192 const Array& args = Array::Handle(Array::New(1)); | 205 const Array& args = Array::Handle(Array::New(1)); |
193 args.SetAt(0, String::Handle(String::New("Infinity or NaN toInt"))); | 206 args.SetAt(0, String::Handle(String::New("Infinity or NaN toInt"))); |
194 Exceptions::ThrowByType(Exceptions::kFormat, args); | 207 Exceptions::ThrowByType(Exceptions::kUnsupported, args); |
195 } | 208 } |
196 double result = trunc(arg.value()); | 209 double result = trunc(arg.value()); |
197 if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) { | 210 if ((Smi::kMinValue <= result) && (result <= Smi::kMaxValue)) { |
198 return Smi::New(static_cast<intptr_t>(result)); | 211 return Smi::New(static_cast<intptr_t>(result)); |
199 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) { | 212 } else if ((Mint::kMinValue <= result) && (result <= Mint::kMaxValue)) { |
200 return Mint::New(static_cast<int64_t>(result)); | 213 return Mint::New(static_cast<int64_t>(result)); |
201 } else { | 214 } else { |
202 return BigintOperations::NewFromDouble(result); | 215 return BigintOperations::NewFromDouble(result); |
203 } | 216 } |
204 } | 217 } |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 | 342 |
330 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 343 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
331 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 344 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
332 // Include negative zero, infinity. | 345 // Include negative zero, infinity. |
333 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 346 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
334 } | 347 } |
335 | 348 |
336 // Add here only functions using/referring to old-style casts. | 349 // Add here only functions using/referring to old-style casts. |
337 | 350 |
338 } // namespace dart | 351 } // namespace dart |
OLD | NEW |