-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConstants.H
99 lines (84 loc) · 2.39 KB
/
Constants.H
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/***********************************************************************
Constants.H
BOOM : Bioinformatics Object Oriented Modules
Copyright (C)2012 William H. Majoros ([email protected]).
This is OPEN SOURCE SOFTWARE governed by the Gnu General Public
License (GPL) version 3, as described at www.opensource.org.
***********************************************************************/
#ifndef INCL_Constants_H
#define INCL_Constants_H
using namespace std;
#include <iostream>
#include <math.h>
#include <fenv.h>
#ifdef __APPLE__
#include <float.h>
#else
#include <values.h>
#endif
#include <limits.h>
//==================================================================
// see /usr/include/limits.h and /usr/include/values.h for others!!!
//==================================================================
namespace BOOM {
const double POSITIVE_INFINITY =-log(0.0);
const double NEGATIVE_INFINITY =log(0.0);
const int LARGEST_INTEGER =INT_MAX;
const int SMALLEST_INTEGER =INT_MIN;
const float LARGEST_FLOAT =FLT_MAX;
const float SMALLEST_FLOAT =FLT_MIN;
const double LARGEST_DOUBLE =DBL_MAX;
const double SMALLEST_DOUBLE =DBL_MIN;
const long LARGEST_LONG_INT =LONG_MAX;
const long SMALLEST_LONG_INT =LONG_MIN;
const unsigned long LARGEST_UNSIGNED_INT =UINT_MAX;
const unsigned long SMALLEST_UNSIGNED_INT =0;
const double PI =acos(-1.0);
const double LOG_0 =log(0.0);
const double LOG_1 =0.0;
#define Endl endl
inline bool isInfinity(double d)
{
return d==NEGATIVE_INFINITY || d==POSITIVE_INFINITY;
}
inline bool isNaN(double d)
{
return isnan(d);
}
inline bool isFinite(double d)
{
return !(isinf(d) || isnan(d));
}
inline double safeAdd(double a,double b)
{
if(isinf(a) || isinf(b)) return NEGATIVE_INFINITY;
return a+b;
}
inline double safeAdd(double a,double b,double c)
{
if(isinf(a) || isinf(b) || isinf(c)) return NEGATIVE_INFINITY;
return a+b+c;
}
inline double safeAdd(double a,double b,double c,double d)
{
if(isinf(a) || isinf(b) || isinf(c) || isinf(d)) return NEGATIVE_INFINITY;
return a+b+c+d;
}
//#ifdef feenableexcept
#ifdef __USE_GNU
inline void catchFloatOverflow()
{
feenableexcept(FE_OVERFLOW);
}
inline bool didOverflow()
{
return fetestexcept(FE_OVERFLOW);
}
#endif
inline void setPrecision(ostream &os,int d)
{
os.setf(ios::fixed);
os.precision(d);
}
}
#endif