LSSTApplications  10.0+286,10.0+36,10.0+46,10.0-2-g4f67435,10.1+152,10.1+37,11.0,11.0+1,11.0-1-g47edd16,11.0-1-g60db491,11.0-1-g7418c06,11.0-2-g04d2804,11.0-2-g68503cd,11.0-2-g818369d,11.0-2-gb8b8ce7
LSSTDataManagementBasePackage
ieee.h
Go to the documentation of this file.
1 // -*- lsst-c++ -*-
2 
3 /*
4  * LSST Data Management System
5  * Copyright 2008, 2009, 2010 LSST Corporation.
6  *
7  * This product includes software developed by the
8  * LSST Project (http://www.lsst.org/).
9  *
10  * This program is free software: you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation, either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the LSST License Statement and
21  * the GNU General Public License along with this program. If not,
22  * see <http://www.lsstcorp.org/LegalNotices/>.
23  */
24 
29 #if !defined(LSST_UTILS_IEEE_H)
30 #define LSST_UTILS_IEEE_H 1
31 
32 #include <string>
33 #include "boost/math/special_functions/fpclassify.hpp"
34 
36 //@brief LSST utilities
37 namespace lsst { namespace utils {
44 /*
45  * We use boost's fpclassify.hpp (which may in turn use the compiler's implementation of isnan if available),
46  * but with one change. Boost doesn't undefine e.g. isnan, but we do. The parentheses in the definition of
47  * e.g. lsst_isnan are to foil any attempt by the compiler to expand e.g. isnan as a macro.
48  */
49 namespace {
50  template <class T>
51  int lsst_fpclassify(T t) {
52  return (boost::math::fpclassify)(t);
53  }
54 
55  template <class T>
56  bool lsst_isfinite(T z) { // Neither infinity nor NaN.
57  return (boost::math::isfinite)(z);
58  }
59 
60  template <class T>
61  bool lsst_isinf(T t) { // Infinity (+ or -).
62  return (boost::math::isinf)(t);
63  }
64 
65  template <class T>
66  bool lsst_isnan(T t) { // NaN.
67  return (boost::math::isnan)(t);
68  }
69 
70  template <class T>
71  bool lsst_isnormal(T t) { // isfinite and not denormalised.
72  return (boost::math::isnormal)(t);
73  }
74 }
75 /*
76  * Now that we have defined e.g. lsst_isnan it's safe to undef any macros
77  */
78 #if defined(fpclassify)
79 # undef fpclassify
80 #endif
81 #if defined(isfinite)
82 # undef isfinite
83 #endif
84 #if defined(isinf)
85 # undef isinf
86 #endif
87 #if defined(isnan)
88 # undef isnan
89 #endif
90 #if defined(isnormal)
91 # undef isnormal
92 #endif
93 
94 template <class T>
95 int fpclassify(T t) {
96  return lsst_fpclassify(t);
97 }
98 
99 template <class T>
100 int isfinite(T t) {
101  return lsst_isfinite(t);
102 }
103 
104 template <class T>
105 int isinf(T t) {
106  return lsst_isinf(t);
107 }
108 
109 template <class T>
110 int isnan(T t) {
111  return lsst_isnan(t);
112 }
113 
114 template <class T>
115 int isnormal(T t) {
116  return lsst_isnormal(t);
117 }
118 
119 }} // namespace lsst::utils
120 
121 #endif
int isnormal(T t)
Definition: ieee.h:115
int isnan(T t)
Definition: ieee.h:110
int isinf(T t)
Definition: ieee.h:105
int isfinite(T t)
Definition: ieee.h:100
int fpclassify(T t)
Definition: ieee.h:95