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

Side by Side Diff: src/conversions.h

Issue 10820047: Make sure double to int conversion is correct. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: addressed comments. Created 8 years, 4 months 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 | « no previous file | src/elements.cc » ('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 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 } 52 }
53 53
54 54
55 inline double SignedZero(bool negative) { 55 inline double SignedZero(bool negative) {
56 return negative ? -0.0 : 0.0; 56 return negative ? -0.0 : 0.0;
57 } 57 }
58 58
59 59
60 // The fast double-to-(unsigned-)int conversion routine does not guarantee 60 // The fast double-to-(unsigned-)int conversion routine does not guarantee
61 // rounding towards zero. 61 // rounding towards zero.
62 // For NaN and values outside the int range, return INT_MIN or INT_MAX.
63 inline int FastD2IChecked(double x) {
64 if (!(x >= INT_MIN)) return INT_MIN; // Negation to catch NaNs.
65 if (x > INT_MAX) return INT_MAX;
66 return static_cast<int>(x);
67 }
68
69
70 // The fast double-to-(unsigned-)int conversion routine does not guarantee
71 // rounding towards zero.
62 // The result is unspecified if x is infinite or NaN, or if the rounded 72 // The result is unspecified if x is infinite or NaN, or if the rounded
63 // integer value is outside the range of type int. 73 // integer value is outside the range of type int.
64 inline int FastD2I(double x) { 74 inline int FastD2I(double x) {
65 // The static_cast convertion from double to int used to be slow, but
66 // as new benchmarks show, now it is much faster than lrint().
67 return static_cast<int>(x); 75 return static_cast<int>(x);
68 } 76 }
69 77
78
70 inline unsigned int FastD2UI(double x); 79 inline unsigned int FastD2UI(double x);
71 80
72 81
73 inline double FastI2D(int x) { 82 inline double FastI2D(int x) {
74 // There is no rounding involved in converting an integer to a 83 // There is no rounding involved in converting an integer to a
75 // double, so this code should compile to a few instructions without 84 // double, so this code should compile to a few instructions without
76 // any FPU pipeline stalls. 85 // any FPU pipeline stalls.
77 return static_cast<double>(x); 86 return static_cast<double>(x);
78 } 87 }
79 88
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 // Additional number to string conversions for the number type. 148 // Additional number to string conversions for the number type.
140 // The caller is responsible for calling free on the returned pointer. 149 // The caller is responsible for calling free on the returned pointer.
141 char* DoubleToFixedCString(double value, int f); 150 char* DoubleToFixedCString(double value, int f);
142 char* DoubleToExponentialCString(double value, int f); 151 char* DoubleToExponentialCString(double value, int f);
143 char* DoubleToPrecisionCString(double value, int f); 152 char* DoubleToPrecisionCString(double value, int f);
144 char* DoubleToRadixCString(double value, int radix); 153 char* DoubleToRadixCString(double value, int radix);
145 154
146 } } // namespace v8::internal 155 } } // namespace v8::internal
147 156
148 #endif // V8_CONVERSIONS_H_ 157 #endif // V8_CONVERSIONS_H_
OLDNEW
« no previous file with comments | « no previous file | src/elements.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698