blob: 90273106cd65193dbef7edeba2825e1c040adabb [file] [log] [blame]
stuartmorgan@chromium.org3876ba72012-07-10 23:11:38 +09001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
license.botf003cfe2008-08-24 09:55:55 +09002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
mmentovai@google.com8dcf71c2008-08-08 02:15:41 +09004
5#ifndef BASE_FLOAT_UTIL_H_
6#define BASE_FLOAT_UTIL_H_
7
8#include "build/build_config.h"
9
10#include <float.h>
thakis@chromium.org3e88bf02013-04-19 07:41:16 +090011
12#include <cmath>
mmentovai@google.com8dcf71c2008-08-08 02:15:41 +090013
14namespace base {
15
miu@chromium.org31939252013-07-23 14:24:46 +090016template <typename Float>
17inline bool IsFinite(const Float& number) {
thakis@chromium.org3e88bf02013-04-19 07:41:16 +090018#if defined(OS_POSIX)
19 return std::isfinite(number) != 0;
mmentovai@google.com8dcf71c2008-08-08 02:15:41 +090020#elif defined(OS_WIN)
21 return _finite(number) != 0;
22#endif
23}
24
miu@chromium.org31939252013-07-23 14:24:46 +090025template <typename Float>
26inline 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
mmentovai@google.com8dcf71c2008-08-08 02:15:41 +090034} // namespace base
35
36#endif // BASE_FLOAT_UTIL_H_