libStatGen Software 1
Loading...
Searching...
No Matches
MathConstant.h
1/*
2 * Copyright (C) 2010 Regents of the University of Michigan
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef __MATHCONSTANT_H__
19#define __MATHCONSTANT_H__
20
21#ifdef _MSC_VER
22#define _USE_MATH_DEFINES
23#endif
24
25#include <math.h>
26#include <stdlib.h>
27
28// Constants for numerical routines
29//
30
31#define TINY 1.0e-30 // A small number
32#define ITMAX 200 // Maximum number of iterations
33#define EPS 3.0e-7 // Relative accuracy
34#define ZEPS 3.0e-10 // Precision around zero
35#define FPMIN 1.0e-30 // Number near the smallest representable number
36#define FPMAX 1.0e+100 // Number near the largest representable number
37#define TOL 1.0e-6 // Zero SVD values below this
38#define GOLD 0.61803399 // Golden ratio
39#define CGOLD 0.38196601 // Complement of golden ratio
40
41inline double square(double a)
42{
43 return a * a;
44}
45inline double sign(double a, double b)
46{
47 return b >= 0 ? fabs(a) : -fabs(a);
48}
49inline double min(double a, double b)
50{
51 return a < b ? a : b;
52}
53inline double max(double a, double b)
54{
55 return a > b ? a : b;
56}
57
58inline int square(int a)
59{
60 return a * a;
61}
62inline int sign(int a, int b)
63{
64 return b >= 0 ? abs(a) : -abs(a);
65}
66inline int min(int a, int b)
67{
68 return a < b ? a : b;
69}
70inline int max(int a, int b)
71{
72 return a > b ? a : b;
73}
74
75// Useful integer quantities
76//
77
78#define THIRTY_BIT_MASK 0x3FFFFFFF
79
80#endif