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

Side by Side Diff: include/core/SkScalar.h

Issue 809443002: Rewrite NaN checks in terms of SkScalarIsNaN() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 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
« no previous file with comments | « include/core/SkRect.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #ifndef SkScalar_DEFINED 8 #ifndef SkScalar_DEFINED
9 #define SkScalar_DEFINED 9 #define SkScalar_DEFINED
10 10
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 /** Returns true if x is not NaN and not infinite 120 /** Returns true if x is not NaN and not infinite
121 */ 121 */
122 static inline bool SkScalarIsFinite(SkScalar x) { 122 static inline bool SkScalarIsFinite(SkScalar x) {
123 // We rely on the following behavior of infinities and nans 123 // We rely on the following behavior of infinities and nans
124 // 0 * finite --> 0 124 // 0 * finite --> 0
125 // 0 * infinity --> NaN 125 // 0 * infinity --> NaN
126 // 0 * NaN --> NaN 126 // 0 * NaN --> NaN
127 SkScalar prod = x * 0; 127 SkScalar prod = x * 0;
128 // At this point, prod will either be NaN or 0 128 // At this point, prod will either be NaN or 0
129 // Therefore we can return (prod == prod) or (0 == prod). 129 // Therefore we can return (prod == prod) or (0 == prod).
130 return prod == prod; 130 return !SkScalarIsNaN(prod);
131 } 131 }
132 132
133 /** 133 /**
134 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5) explicitly using 134 * Variant of SkScalarRoundToInt, that performs the rounding step (adding 0.5) explicitly using
135 * double, to avoid possibly losing the low bit(s) of the answer before calling floor(). 135 * double, to avoid possibly losing the low bit(s) of the answer before calling floor().
136 * 136 *
137 * This routine will likely be slower than SkScalarRoundToInt(), and should onl y be used when the 137 * This routine will likely be slower than SkScalarRoundToInt(), and should onl y be used when the
138 * extra precision is known to be valuable. 138 * extra precision is known to be valuable.
139 * 139 *
140 * In particular, this catches the following case: 140 * In particular, this catches the following case:
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 SkASSERT(n >= 0); 241 SkASSERT(n >= 0);
242 for (int i = 0; i < n; ++i) { 242 for (int i = 0; i < n; ++i) {
243 if (a[i] != b[i]) { 243 if (a[i] != b[i]) {
244 return false; 244 return false;
245 } 245 }
246 } 246 }
247 return true; 247 return true;
248 } 248 }
249 249
250 #endif 250 #endif
OLDNEW
« no previous file with comments | « include/core/SkRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698