Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(163)

Side by Side Diff: runtime/platform/floating_point_win.cc

Issue 11411188: Fix floating point issues on Windows. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: ndx_x, ndx_y -> index_x, index_y. Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « runtime/platform/floating_point_win.h ('k') | runtime/platform/globals.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
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.
4
5 #include <math.h>
6 #include <limits>
7
8 #include "platform/globals.h"
9
10 // Taken from third_party/v8/src/platform-win32.cc
11 double fmod_ieee(double x, double y) {
12 // x is dividend, y is divisor.
13 // Work around MS fmod bugs. ISO Standard says:
14 // If dividend is finite and divisor is an infinity or
15 // dividend is a zero and divisor is nonzero finite,
16 // then dividend is returned.
17 if (!(_finite(x) && (!_finite(y) && !isnan(y))) &&
18 !(x == 0 && (y != 0 && _finite(y)))) {
19 x = fmod(x, y);
20 }
21 return x;
22 }
23
24 // Bring MSVC atan2 behavior in line with ISO standard.
25 // MSVC atan2 returns NaN when x and y are either +infinity or -infinity.
26 // Per ISO standard:
27 // - If y is +/-infinity and x is -infinity, +/-3*pi/4 is returned.
28 // - If y is +/-infinity and x is +infinity, +/-pi/4 is returned.
29 double atan2_ieee(double x, double y) {
30 int cls_x = _fpclass(x);
31 int cls_y = _fpclass(y);
32 if (((cls_x & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0) &&
33 ((cls_y & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0)) {
34 // atan2 values at infinities listed above are the same as values
35 // at (+/-1, +/-1). index_x is 0, when x is +infinty, 1 when x is -infinty.
36 // Same is with index_y.
37 int index_x = (cls_x & _FPCLASS_PINF) != 0 ? 0 : 1;
38 int index_y = (cls_y & _FPCLASS_PINF) != 0 ? 0 : 1;
39 static double atans_at_infinities[2][2] =
40 { { atan2(1., 1.), atan2(1., -1.) },
41 { atan2(-1., 1.), atan2(-1., -1.) } };
42 return atans_at_infinities[index_x][index_y];
43 } else {
44 return atan2(x, y);
45 }
46 }
OLDNEW
« no previous file with comments | « runtime/platform/floating_point_win.h ('k') | runtime/platform/globals.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698