OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_FLOAT_UTIL_H_ | 5 #ifndef BASE_FLOAT_UTIL_H_ |
6 #define BASE_FLOAT_UTIL_H_ | 6 #define BASE_FLOAT_UTIL_H_ |
7 | 7 |
8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
9 | 9 |
10 #include <float.h> | 10 #include <float.h> |
11 | 11 |
12 #include <cmath> | 12 #include <cmath> |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 inline bool IsFinite(const double& number) { | 16 template <typename Float> |
| 17 inline bool IsFinite(const Float& number) { |
17 #if defined(OS_POSIX) | 18 #if defined(OS_POSIX) |
18 return std::isfinite(number) != 0; | 19 return std::isfinite(number) != 0; |
19 #elif defined(OS_WIN) | 20 #elif defined(OS_WIN) |
20 return _finite(number) != 0; | 21 return _finite(number) != 0; |
21 #endif | 22 #endif |
22 } | 23 } |
23 | 24 |
| 25 template <typename Float> |
| 26 inline bool IsNaN(const Float& number) { |
| 27 #if defined(OS_POSIX) |
| 28 return std::isnan(number) != 0; |
| 29 #elif defined(OS_WIN) |
| 30 return _isnan(number) != 0; |
| 31 #endif |
| 32 } |
| 33 |
24 } // namespace base | 34 } // namespace base |
25 | 35 |
26 #endif // BASE_FLOAT_UTIL_H_ | 36 #endif // BASE_FLOAT_UTIL_H_ |
OLD | NEW |