Debian Codegraph @

3rdparty/dissection/src/Compiler/OptionLibrary.hpp

raw
1 /*! \file OptionLibrary.hpp
2 \brief compatibility for Microsoft compiler
3 \author Atsushi Suzuki, Laboratoire Jacques-Louis Lions
4 \date Feb. 23th 2013
5 \date Feb. 29th 2016
6 \date Nov. 30th 2016
7 */
8
9 // This file is part of Dissection
10 //
11 // Dissection is free software: you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation, either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // Linking Dissection statically or dynamically with other modules is making
17 // a combined work based on Disssection. Thus, the terms and conditions of
18 // the GNU General Public License cover the whole combination.
19 //
20 // As a special exception, the copyright holders of Dissection give you
21 // permission to combine Dissection program with free software programs or
22 // libraries that are released under the GNU LGPL and with independent modules
23 // that communicate with Dissection solely through the Dissection-fortran
24 // interface. You may copy and distribute such a system following the terms of
25 // the GNU GPL for Dissection and the licenses of the other code concerned,
26 // provided that you include the source code of that other code when and as
27 // the GNU GPL requires distribution of source code and provided that you do
28 // not modify the Dissection-fortran interface.
29 //
30 // Note that people who make modified versions of Dissection are not obligated
31 // to grant this special exception for their modified versions; it is their
32 // choice whether to do so. The GNU General Public License gives permission to
33 // release a modified version without this exception; this exception also makes
34 // it possible to release a modified version which carries forward this
35 // exception. If you modify the Dissection-fortran interface, this exception
36 // does not apply to your modified version of Dissection, and you must remove
37 // this exception when you distribute your modified version.
38 //
39 // This exception is an additional permission under section 7 of the GNU
40 // General Public License, version 3 ("GPLv3")
41 //
42 // Dissection is distributed in the hope that it will be useful,
43 // but WITHOUT ANY WARRANTY; without even the implied warranty of
44 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
45 // GNU General Public License for more details.
46 //
47 // You should have received a copy of the GNU General Public License
48 // along with Dissection. If not, see <http://www.gnu.org/licenses/>.
49 //
50
51 #ifndef _COMPILER_OPTIONLIBRARY_H
52 # define _COMPILER_OPTIONLIBRARY_H
53
54 #ifdef _MSC_VER
55 #define NOMINMAX
56 #define _USE_MATH_DEFINES
57 #if (_MSC_VER < 1500) // in case of C99 is not supported
58 # define M_PI 3.14159265358979323846264338327950288
59 double log2(double x) {
60 return (log(x) / log(2.0));
61 }
62 #else
63 # include <cmath>
64 #endif
65 # include <process.h>
66 # include <iterator>
67 #else
68 # include <stdlib.h>
69 # include <unistd.h>
70 #endif
71
72 #ifdef SX_ACE
73 #include <string>
74 #include <cstdlib>
75 #endif
76
77 static inline bool random_bool()
78 {
79 #ifdef _MSC_VER
80 double r = (double)rand() / (double)RAND_MAX;
81 return (r < 0.5 ? true : false);
82 #else
83 #ifdef SX_ACE
84 double r = (double)rand() / (double)RAND_MAX;
85 return (r < 0.5 ? true : false);
86 #else
87 #ifdef __SUNPRO_CC
88 return (random() < 1073741824L); // 2^31 / 2
89 #else
90 return (random() < (RAND_MAX / 2L));
91 #endif
92 #endif
93 #endif
94 }
95
96 static inline int get_process_id()
97 {
98 #ifdef _MSC_VER
99 return (int)_getpid();
100 #else
101 return (int)getpid();
102 #endif
103 }
104
105 // Intel compiler + older GNU C++ library may not have to_string()
106 // SX_ACE does not have
107 #ifdef NO_TO_STRING
108 #include <string>
109 #include <cstdio>
110 inline std::string to_string(int num)
111 {
112 char buf[256];
113 sprintf(buf, "%d", num);
114 std::string st = buf;
115 return st;
116 }
117 #endif
118
119 #endif