Index: runtime/platform/floating_point_win.cc |
diff --git a/runtime/platform/floating_point_win.cc b/runtime/platform/floating_point_win.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..bb34d9bc293a4d1ffb7f3206b23197e4401941f8 |
--- /dev/null |
+++ b/runtime/platform/floating_point_win.cc |
@@ -0,0 +1,44 @@ |
+// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
+// for details. All rights reserved. Use of this source code is governed by a |
+// BSD-style license that can be found in the LICENSE file. |
+ |
+#include <math.h> |
+#include <limits> |
+ |
+#include "platform/globals.h" |
+ |
+// Taken from third_party/v8/src/platform-win32.cc |
+double modulo(double x, double y) { |
+ // Work around MS fmod bugs. ISO Standard says: |
+ // dividend is finite and divisor is an infinity => result equals dividend |
Mads Ager (google)
2012/11/29 09:36:36
Nit picking: could you start with a capital letter
aam-me
2012/11/29 12:39:53
Done.
|
+ // dividend is a zero and divisor is nonzero finite => result equals dividend |
+ if (!(_finite(x) && (!_finite(y) && !isnan(y))) && |
+ !(x == 0 && (y != 0 && _finite(y)))) { |
+ x = fmod(x, y); |
+ } |
+ return x; |
+} |
+ |
+// Bring MSVC atan2 behavior in line with ISO standard. |
+// MSVC atan2 returns NaN when x and y are either +inf or -inf. |
+// Per ISO standard: |
+// - If y is +inf(-infinity) and x is -inf, +3*pi/4 (-3*pi/4) is returned. |
Mads Ager (google)
2012/11/29 09:36:36
Could you write out 'infinity' for all occurrences
aam-me
2012/11/29 12:39:53
Done.
|
+// - If y is +inf(-infinity) and x is +inf, +pi/4 (-pi/4) is returned. |
+double atan2_ieee(double x, double y) { |
+ int cls_x = _fpclass(x); |
+ int cls_y = _fpclass(y); |
+ if (((cls_x & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0) && |
+ ((cls_y & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0)) { |
+ // atan2 values at infinities listed above are the same as values |
+ // at (+/-1, +/-1). ndx_x is 0, when x is +inf, 1 when x is -inf. |
+ // Same is with ndx_y. |
+ int ndx_x = (cls_x & _FPCLASS_PINF) != 0? 0: 1; |
Mads Ager (google)
2012/11/29 09:36:36
Please add spaces and write out index:
int index_
aam-me
2012/11/29 12:39:53
Done.
|
+ int ndx_y = (cls_y & _FPCLASS_PINF) != 0? 0: 1; |
+ static double atans_at_infinities[2][2] = |
+ { { atan2(1., 1.), atan2(1., -1.) }, |
+ { atan2(-1., 1.), atan2(-1., -1.) } }; |
+ return atans_at_infinities[ndx_x][ndx_y]; |
+ } else { |
+ return atan2(x, y); |
+ } |
+} |