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

Side by Side Diff: runtime/platform/c99_support_win.h

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/lib/math.cc ('k') | runtime/platform/floating_point.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef PLATFORM_C99_SUPPORT_WIN_H_ 5 #ifndef PLATFORM_C99_SUPPORT_WIN_H_
6 #define PLATFORM_C99_SUPPORT_WIN_H_ 6 #define PLATFORM_C99_SUPPORT_WIN_H_
7 7
8 // Visual C++ is missing a bunch of C99 math macros and 8 // Visual C++ is missing a bunch of C99 math macros and
9 // functions. Define them here. 9 // functions. Define them here.
10 10
(...skipping 30 matching lines...) Expand all
41 41
42 static inline double trunc(double x) { 42 static inline double trunc(double x) {
43 if (x < 0) { 43 if (x < 0) {
44 return ceil(x); 44 return ceil(x);
45 } else { 45 } else {
46 return floor(x); 46 return floor(x);
47 } 47 }
48 } 48 }
49 49
50 static inline double round(double x) { 50 static inline double round(double x) {
51 if (x < 0) { 51 if (!_finite(x)) {
52 return ceil(x - 0.5); 52 return x;
53 }
54
55 double intpart;
56 double fractpart = modf(x, &intpart);
57
58 if (fractpart >= 0.5) {
59 return intpart + 1;
60 } else if (fractpart > -0.5) {
61 return intpart;
53 } else { 62 } else {
54 return floor(x + 0.5); 63 return intpart - 1;
55 } 64 }
56 } 65 }
57 66
58 #endif // PLATFORM_C99_SUPPORT_WIN_H_ 67 #endif // PLATFORM_C99_SUPPORT_WIN_H_
OLDNEW
« no previous file with comments | « runtime/lib/math.cc ('k') | runtime/platform/floating_point.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698