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

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: Moved round() back to static inline function. Redid the changes lost from previous patch. 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
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 modulo(double x, double y) {
12 // Work around MS fmod bugs. ISO Standard says:
13 // 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.
14 // dividend is a zero and divisor is nonzero finite => result equals dividend
15 if (!(_finite(x) && (!_finite(y) && !isnan(y))) &&
16 !(x == 0 && (y != 0 && _finite(y)))) {
17 x = fmod(x, y);
18 }
19 return x;
20 }
21
22 // Bring MSVC atan2 behavior in line with ISO standard.
23 // MSVC atan2 returns NaN when x and y are either +inf or -inf.
24 // Per ISO standard:
25 // - 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.
26 // - If y is +inf(-infinity) and x is +inf, +pi/4 (-pi/4) is returned.
27 double atan2_ieee(double x, double y) {
28 int cls_x = _fpclass(x);
29 int cls_y = _fpclass(y);
30 if (((cls_x & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0) &&
31 ((cls_y & (_FPCLASS_PINF | _FPCLASS_NINF)) != 0)) {
32 // atan2 values at infinities listed above are the same as values
33 // at (+/-1, +/-1). ndx_x is 0, when x is +inf, 1 when x is -inf.
34 // Same is with ndx_y.
35 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.
36 int ndx_y = (cls_y & _FPCLASS_PINF) != 0? 0: 1;
37 static double atans_at_infinities[2][2] =
38 { { atan2(1., 1.), atan2(1., -1.) },
39 { atan2(-1., 1.), atan2(-1., -1.) } };
40 return atans_at_infinities[ndx_x][ndx_y];
41 } else {
42 return atan2(x, y);
43 }
44 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698