source: CIVL/examples/compare/provesa/ADFirstAidKit/profile/numeric-utils.h

main
Last change on this file was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 919 bytes
Line 
1#ifndef NUMERIC_UTILS_H
2#define NUMERIC_UTILS_H 1
3
4#include <limits>
5
6template <typename T> bool is_nan(T number) {
7 using namespace std;
8 if (numeric_limits<T>::is_integer)
9 return false;
10 return ! (number == number);
11}
12
13template <int N, typename T> struct _power {
14 T value(T a) {
15 return a * _power<N-1,T>(a);
16 }
17};
18template <typename T> struct _power<0,T> {
19 T value(T a) {
20 return 1;
21 }
22};
23
24template <int N, typename T> T power(T a) {
25 return _power<N,T>().value(a);
26}
27
28template <typename T> bool is_finite(T number) {
29 using namespace std;
30 if (numeric_limits<T>::is_integer)
31 return true;
32 const T inf = numeric_limits<T>::infinity();
33 if (number == inf || is_nan(number)) // NaN detection
34 return false;
35 return true;
36};
37
38#endif
Note: See TracBrowser for help on using the repository browser.