1 | /* -*- mode: C++; indent-tabs-mode: nil; -*- |
---|
2 | * |
---|
3 | * This file is a part of LEMON, a generic C++ optimization library. |
---|
4 | * |
---|
5 | * Copyright (C) 2003-2013 |
---|
6 | * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport |
---|
7 | * (Egervary Research Group on Combinatorial Optimization, EGRES). |
---|
8 | * |
---|
9 | * Permission to use, modify and distribute this software is granted |
---|
10 | * provided that this copyright notice appears in all copies. For |
---|
11 | * precise terms see the accompanying LICENSE file. |
---|
12 | * |
---|
13 | * This software is provided "AS IS" with no warranty of any kind, |
---|
14 | * express or implied, and with no claim as to its suitability for any |
---|
15 | * purpose. |
---|
16 | * |
---|
17 | */ |
---|
18 | |
---|
19 | #ifndef LEMON_MATH_H |
---|
20 | #define LEMON_MATH_H |
---|
21 | |
---|
22 | ///\ingroup misc |
---|
23 | ///\file |
---|
24 | ///\brief Some extensions to the standard \c cmath library. |
---|
25 | /// |
---|
26 | ///Some extensions to the standard \c cmath library. |
---|
27 | /// |
---|
28 | ///This file includes the standard math library (cmath). |
---|
29 | |
---|
30 | #include<cmath> |
---|
31 | |
---|
32 | namespace lemon { |
---|
33 | |
---|
34 | /// \addtogroup misc |
---|
35 | /// @{ |
---|
36 | |
---|
37 | /// The Euler constant |
---|
38 | const long double E = 2.7182818284590452353602874713526625L; |
---|
39 | /// log_2(e) |
---|
40 | const long double LOG2E = 1.4426950408889634073599246810018921L; |
---|
41 | /// log_10(e) |
---|
42 | const long double LOG10E = 0.4342944819032518276511289189166051L; |
---|
43 | /// ln(2) |
---|
44 | const long double LN2 = 0.6931471805599453094172321214581766L; |
---|
45 | /// ln(10) |
---|
46 | const long double LN10 = 2.3025850929940456840179914546843642L; |
---|
47 | /// pi |
---|
48 | const long double PI = 3.1415926535897932384626433832795029L; |
---|
49 | /// pi/2 |
---|
50 | const long double PI_2 = 1.5707963267948966192313216916397514L; |
---|
51 | /// pi/4 |
---|
52 | const long double PI_4 = 0.7853981633974483096156608458198757L; |
---|
53 | /// sqrt(2) |
---|
54 | const long double SQRT2 = 1.4142135623730950488016887242096981L; |
---|
55 | /// 1/sqrt(2) |
---|
56 | const long double SQRT1_2 = 0.7071067811865475244008443621048490L; |
---|
57 | |
---|
58 | ///Check whether the parameter is NaN or not |
---|
59 | |
---|
60 | ///This function checks whether the parameter is NaN or not. |
---|
61 | ///Is should be equivalent with std::isnan(), but it is not |
---|
62 | ///provided by all compilers. |
---|
63 | inline bool isNaN(double v) |
---|
64 | { |
---|
65 | return v!=v; |
---|
66 | } |
---|
67 | |
---|
68 | ///Round a value to its closest integer |
---|
69 | inline double round(double r) { |
---|
70 | return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); |
---|
71 | } |
---|
72 | |
---|
73 | /// @} |
---|
74 | |
---|
75 | } //namespace lemon |
---|
76 | |
---|
77 | #endif //LEMON_MATH_H |
---|