| 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/double_conversion.h" | 11 #include "vm/double_conversion.h" |
| 11 #include "vm/exceptions.h" | 12 #include "vm/exceptions.h" |
| 12 #include "vm/native_entry.h" | 13 #include "vm/native_entry.h" |
| 13 #include "vm/object.h" | 14 #include "vm/object.h" |
| 14 #include "vm/symbols.h" | 15 #include "vm/symbols.h" |
| 15 | 16 |
| 16 namespace dart { | 17 namespace dart { |
| 17 | 18 |
| 18 DECLARE_FLAG(bool, trace_intrinsified_natives); | 19 DECLARE_FLAG(bool, trace_intrinsified_natives); |
| 19 | 20 |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 96 } | 97 } |
| 97 return DoubleToInteger(trunc(left / right), | 98 return DoubleToInteger(trunc(left / right), |
| 98 "Result of truncating division is Infinity or NaN"); | 99 "Result of truncating division is Infinity or NaN"); |
| 99 } | 100 } |
| 100 | 101 |
| 101 | 102 |
| 102 DEFINE_NATIVE_ENTRY(Double_modulo, 2) { | 103 DEFINE_NATIVE_ENTRY(Double_modulo, 2) { |
| 103 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 104 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
| 104 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 105 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
| 105 double right = right_object.value(); | 106 double right = right_object.value(); |
| 106 | 107 return Double::New(DartModulo(left, right)); |
| 107 double remainder = fmod_ieee(left, right); | |
| 108 if (remainder == 0.0) { | |
| 109 // We explicitely switch to the positive 0.0 (just in case it was negative). | |
| 110 remainder = +0.0; | |
| 111 } else if (remainder < 0) { | |
| 112 if (right < 0) { | |
| 113 remainder -= right; | |
| 114 } else { | |
| 115 remainder += right; | |
| 116 } | |
| 117 } | |
| 118 return Double::New(remainder); | |
| 119 } | 108 } |
| 120 | 109 |
| 121 | 110 |
| 122 DEFINE_NATIVE_ENTRY(Double_remainder, 2) { | 111 DEFINE_NATIVE_ENTRY(Double_remainder, 2) { |
| 123 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); | 112 double left = Double::CheckedHandle(arguments->NativeArgAt(0)).value(); |
| 124 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); | 113 GET_NON_NULL_NATIVE_ARGUMENT(Double, right_object, arguments->NativeArgAt(1)); |
| 125 double right = right_object.value(); | 114 double right = right_object.value(); |
| 126 return Double::New(fmod_ieee(left, right)); | 115 return Double::New(fmod_ieee(left, right)); |
| 127 } | 116 } |
| 128 | 117 |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 322 |
| 334 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { | 323 DEFINE_NATIVE_ENTRY(Double_getIsNegative, 1) { |
| 335 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); | 324 const Double& arg = Double::CheckedHandle(arguments->NativeArgAt(0)); |
| 336 // Include negative zero, infinity. | 325 // Include negative zero, infinity. |
| 337 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); | 326 return Bool::Get(signbit(arg.value()) && !isnan(arg.value())); |
| 338 } | 327 } |
| 339 | 328 |
| 340 // Add here only functions using/referring to old-style casts. | 329 // Add here only functions using/referring to old-style casts. |
| 341 | 330 |
| 342 } // namespace dart | 331 } // namespace dart |
| OLD | NEW |