QuantLib: a free/open-source library for quantitative finance
fully annotated source code - version 1.34
Loading...
Searching...
No Matches
qldefines.hpp
Go to the documentation of this file.
1/* -*- mode: c++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2
3/*
4 Copyright (C) 2000, 2001, 2002, 2003 RiskMap srl
5 Copyright (C) 2003, 2004, 2005, 2006, 2007 StatPro Italia srl
6 Copyright (C) 2015 CompatibL
7
8 This file is part of QuantLib, a free-software/open-source library
9 for financial quantitative analysts and developers - http://quantlib.org/
10
11 QuantLib is free software: you can redistribute it and/or modify it
12 under the terms of the QuantLib license. You should have received a
13 copy of the license along with this program; if not, please email
14 <quantlib-dev@lists.sf.net>. The license is also available online at
15 <http://quantlib.org/license.shtml>.
16
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the license for more details.
20*/
21
22/*! \file qldefines.hpp
23 \brief Global definitions and compiler switches.
24*/
25
26#ifndef quantlib_defines_hpp
27/* install-hook */
28#define quantlib_defines_hpp
29
30#ifdef _MSC_VER
31/* Microsoft-specific, but needs to be defined before
32 including <boost/config.hpp> which somehow includes
33 <math.h> under VC++10
34*/
35#define _USE_MATH_DEFINES
36#endif
37
38#include <boost/config.hpp>
39#include <boost/version.hpp>
40#if BOOST_VERSION < 104800
41 #error using an old version of Boost, please update.
42#endif
43#if !defined(BOOST_ENABLE_ASSERT_HANDLER)
44 #define BOOST_ENABLE_ASSERT_HANDLER
45#endif
46
47/* This allows one to include a given file at this point by
48 passing it as a compiler define (e.g., -DQL_INCLUDE_FIRST=foo.hpp).
49
50 The idea is to provide a hook for defining QL_REAL and at the
51 same time including any necessary headers for the new type.
52*/
53#define INCLUDE_FILE(F) INCLUDE_FILE_(F)
54#define INCLUDE_FILE_(F) #F
55#ifdef QL_INCLUDE_FIRST
56# include INCLUDE_FILE(QL_INCLUDE_FIRST)
57#endif
58#undef INCLUDE_FILE_
59#undef INCLUDE_FILE
60
61/* Eventually these might go into userconfig.hpp.
62 For the time being, we hard code them here.
63 They can be overridden by passing the #define to the compiler.
64*/
65#ifndef QL_INTEGER
66# define QL_INTEGER int
67#endif
68
69#ifndef QL_BIG_INTEGER
70# define QL_BIG_INTEGER long
71#endif
72
73#ifndef QL_REAL
74# define QL_REAL double
75#endif
76
77
78/*! \defgroup macros QuantLib macros
79
80 Global definitions and a few macros which help porting the
81 code to different compilers.
82
83 @{
84*/
85
86#if (defined(_DEBUG) || defined(DEBUG))
87 #define QL_DEBUG
88#endif
89
90#if defined(HAVE_CONFIG_H) // Dynamically created by configure
91 #include <ql/config.hpp>
92/* Use BOOST_MSVC instead of _MSC_VER since some other vendors (Metrowerks,
93 for example) also #define _MSC_VER
94*/
95#elif defined(BOOST_MSVC) // Microsoft Visual C++
96 #include <ql/config.msvc.hpp>
97#elif defined(__MINGW32__) // Minimalistic GNU for Windows
98 #include <ql/config.mingw.hpp>
99#elif defined(__SUNPRO_CC) // Sun Studio
100 #include <ql/config.sun.hpp>
101#else // We hope that the compiler follows ANSI
102 #include <ql/config.ansi.hpp>
103#endif
104
105
106// extra debug checks
107#ifdef QL_DEBUG
108 #ifndef QL_EXTRA_SAFETY_CHECKS
109 #define QL_EXTRA_SAFETY_CHECKS
110 #endif
111#endif
112
113#ifdef QL_ENABLE_THREAD_SAFE_OBSERVER_PATTERN
114 #if BOOST_VERSION < 105800
115 #error Boost version 1.58 or higher is required for the thread-safe observer pattern
116 #endif
117#endif
118
119#ifdef QL_ENABLE_PARALLEL_UNIT_TEST_RUNNER
120 #if BOOST_VERSION < 105900
121 #error Boost version 1.59 or higher is required for the parallel unit test runner
122 #endif
123#endif
124
125// ensure that needed math constants are defined
126#include <ql/mathconstants.hpp>
127
128
129// import global functions into std namespace
130#if defined(BOOST_NO_STDC_NAMESPACE)
131 #include <cmath>
132 namespace std {
133 using ::sqrt; using ::abs; using ::fabs;
134 using ::exp; using ::log; using ::pow;
135 using ::sin; using ::cos; using ::asin; using ::acos;
136 using ::sinh; using ::cosh;
137 using ::floor; using ::fmod; using ::modf;
138 }
139#endif
140
141
142/*! \defgroup limitMacros Numeric limits
143
144 Some compilers do not give an implementation of
145 <code><limits></code> yet. For the code to be portable
146 these macros should be used instead of the corresponding method of
147 <code>std::numeric_limits</code> or the corresponding macro
148 defined in <code><limits.h></code>.
149
150 @{
151*/
152/*! \def QL_MIN_INTEGER
153 Defines the value of the largest representable negative integer value
154*/
155/*! \def QL_MAX_INTEGER
156 Defines the value of the largest representable integer value
157*/
158/*! \def QL_MIN_REAL
159 Defines the value of the largest representable negative
160 floating-point value
161*/
162/*! \def QL_MIN_POSITIVE_REAL
163 Defines the value of the smallest representable positive double value
164*/
165/*! \def QL_MAX_REAL
166 Defines the value of the largest representable floating-point value
167*/
168/*! \def QL_EPSILON
169 Defines the machine precision for operations over doubles
170*/
171#include <limits>
172// limits used as such
173#define QL_MIN_INTEGER ((std::numeric_limits<QL_INTEGER>::min)())
174#define QL_MAX_INTEGER ((std::numeric_limits<QL_INTEGER>::max)())
175#define QL_MIN_REAL -((std::numeric_limits<QL_REAL>::max)())
176#define QL_MAX_REAL ((std::numeric_limits<QL_REAL>::max)())
177#define QL_MIN_POSITIVE_REAL ((std::numeric_limits<QL_REAL>::min)())
178#define QL_EPSILON ((std::numeric_limits<QL_REAL>::epsilon)())
179/*! @} */
180
181/*! @} */
182
183
184// For the time being we're keeping a QL_DEPRECATED macro because
185// of <https://stackoverflow.com/questions/38378693/>. We need to
186// use it to deprecate constructors until we drop support for VC++2015.
187// Other features (methods, typedefs etc.) can use [[deprecated]] and
188// possibly add a message.
189
190// emit warning when using deprecated features
191// clang-format off
192#if defined(BOOST_MSVC) // Microsoft Visual C++
193# define QL_DEPRECATED __declspec(deprecated)
194# define QL_DEPRECATED_DISABLE_WARNING \
195 __pragma(warning(push)) \
196 __pragma(warning(disable : 4996))
197# define QL_DEPRECATED_ENABLE_WARNING \
198 __pragma(warning(pop))
199#elif defined(__GNUC__)
200# define QL_DEPRECATED __attribute__((deprecated))
201# define QL_DEPRECATED_DISABLE_WARNING \
202 _Pragma("GCC diagnostic push") \
203 _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"")
204# define QL_DEPRECATED_ENABLE_WARNING \
205 _Pragma("GCC diagnostic pop")
206#elif defined(__clang__)
207# define QL_DEPRECATED __attribute__((deprecated))
208# define QL_DEPRECATED_DISABLE_WARNING \
209 _Pragma("clang diagnostic push") \
210 _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"")
211# define QL_DEPRECATED_ENABLE_WARNING \
212 _Pragma("clang diagnostic pop")
213#else
214// we don't know how to enable it, just define the macros away
215# define QL_DEPRECATED
216# define QL_DEPRECATED_DISABLE_WARNING
217# define QL_DEPRECATED_ENABLE_WARNING
218#endif
219// clang-format on
220
221#endif
STL namespace.