EGSnrc C++ class library  Report PIRS-898 (2021)
Iwan Kawrakow, Ernesto Mainegra-Hing, Frederic Tessier, Reid Townson and Blake Walters
egs_math.h
Go to the documentation of this file.
1 /*
2 ###############################################################################
3 #
4 # EGSnrc egs++ math headers
5 # Copyright (C) 2015 National Research Council Canada
6 #
7 # This file is part of EGSnrc.
8 #
9 # EGSnrc is free software: you can redistribute it and/or modify it under
10 # the terms of the GNU Affero General Public License as published by the
11 # Free Software Foundation, either version 3 of the License, or (at your
12 # option) any later version.
13 #
14 # EGSnrc is distributed in the hope that it will be useful, but WITHOUT ANY
15 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 # FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
17 # more details.
18 #
19 # You should have received a copy of the GNU Affero General Public License
20 # along with EGSnrc. If not, see <http://www.gnu.org/licenses/>.
21 #
22 ###############################################################################
23 #
24 # Author: Iwan Kawrakow, 2005
25 #
26 # Contributors:
27 #
28 ###############################################################################
29 */
30 
31 
37 #ifndef EGS_MATH_
38 #define EGS_MATH_
39 
40 #ifdef MISSING
41  #include "missing.h"
42 #endif
43 
44 #ifdef NO_CMATH
45  #include <math.h>
46 #else
47  #include <cmath>
48 #endif
49 
50 // M_PI is not defined after including cmath for the MS visual studio compiler?
51 #ifndef M_PI
52  #define M_PI 3.14159265358979323846
53 #endif
54 
55 // Some C++ compilers don't have a proper implementation of abs() for
56 // all types => use a macro instead.
57 #ifdef DONT_HAVE_ABS
58  #ifdef abs
59  #undef abs
60  #endif
61  #define abs(a) ((a) >= 0 ? (a) : -(a))
62 #endif
63 
64 // Some C++ compilers don't know anything about min/max after including
65 // cmath.
66 #ifdef DONT_HAVE_MINMAX
67  #ifdef min
68  #undef min
69  #endif
70  #ifdef max
71  #undef max
72  #endif
73  #define max(a, b) ((a) > (b) ? (a) : (b))
74  #define min(a, b) ((a) < (b) ? (a) : (b))
75 #endif
76 
77 // this one is needed for the SGI C++ compiler.
78 #ifdef STD_SQRT
79  #define sqrt(a) std::sqrt(a)
80 #endif
81 
82 #endif