Rosetta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
numbers.hh
Go to the documentation of this file.
1 // -*- mode:c++;tab-width:2;indent-tabs-mode:t;show-trailing-whitespace:t;rm-trailing-spaces:t -*-
2 // vi: set ts=2 noet:
3 //
4 // (c) Copyright Rosetta Commons Member Institutions.
5 // (c) This file is part of the Rosetta software suite and is made available under license.
6 // (c) The Rosetta software is developed by the contributing members of the Rosetta Commons.
7 // (c) For more information, see http://www.rosettacommons.org. Questions about this can be
8 // (c) addressed to University of Washington UW TechTransfer, email: license@u.washington.edu.
9 
10 /// @file utility/numbers.hh
11 /// @brief Brief utility classes for numeric usage
12 /// @details For more complex numeric utilties, see the numeric namespace
13 /// @author Rocco Moretti
14 
15 #ifndef INCLUDED_utility_numbers_hh
16 #define INCLUDED_utility_numbers_hh
17 
18 #include <platform/types.hh>
19 
20 #include <limits>
21 #include <cmath>
22 
23 
24 #if defined(WIN32) && !defined(__CYGWIN__)
25 #include <float.h>
26 namespace std {
27 inline int isnan(double x) { return _isnan(x); }
28 inline int isinf(double x) { return !_finite(x); }
29 }
30 inline double round(double x) { return x < 0.0 ? ceil(x - 0.5) : floor(x + 0.5); }
31 inline double copysign(double x, double y) { return _copysign(x, y); }
32 #endif
33 
34 namespace utility {
35 
36 /// @brief Get a numeric value for Size that represents an "undefined" value
37 inline
39  return std::numeric_limits< platform::Size >::max(); // Choice of value same as the BCL (Meiler Lab)
40 }
41 
42 /// @brief Check if a Size is undefined (i.e has the same value as utility::get_undefined_size() )
43 inline
44 bool is_undefined( platform::Size const & val) {
45  return val == get_undefined_size();
46 }
47 
48 /// @brief Get a numeric value for Real that represents an "undefined" value
49 inline
51  return std::numeric_limits< platform::Real >::quiet_NaN(); // Choice of value same as the BCL (Meiler Lab)
52 }
53 
54 /// @brief Check if a Real is undefined (i.e has the same value as utility::get_undefined_real() )
55 inline
56 bool is_undefined( platform::Real const & val) {
57  return std::isnan( val ) || std::isinf( val );
58 }
59 
60 inline
61 bool is_nan( platform::Real const & val) {
62  return std::isnan( val );
63 }
64 
65 inline
66 bool is_inf( platform::Real const & val) {
67  return std::isinf( val );
68 }
69 
70 inline
72  return ::round(val);
73 }
74 
75 inline
77  return ::copysign(x, y);
78 }
79 
80 } // utility
81 
82 #endif
bool isnan(T value)
portable check to see if a value is NaN.
Definition: util.hh:47
platform::Size get_undefined_size()
Get a numeric value for Size that represents an "undefined" value.
Definition: numbers.hh:38
def x
double Real
Definition: types.hh:45
bool isinf(T value)
Definition: util.hh:52
bool is_inf(platform::Real const &val)
Definition: numbers.hh:66
platform::Real copysign(platform::Real const &x, platform::Real const &y)
Definition: numbers.hh:76
bool is_nan(platform::Real const &val)
Definition: numbers.hh:61
platform::Real get_undefined_real()
Get a numeric value for Real that represents an "undefined" value.
Definition: numbers.hh:50
core::Real round(core::Real d, core::Size digits)
platform::Real round(platform::Real const &val)
Definition: numbers.hh:71
bool is_undefined(platform::Size const &val)
Check if a Size is undefined (i.e has the same value as utility::get_undefined_size() ) ...
Definition: numbers.hh:44
std::size_t Size
Definition: types.hh:37
static T max(T x, T y)
Definition: Svm.cc:19
def y