]> git.lyx.org Git - lyx.git/blob - src/support/lyxlib.h
Fix text direction issue for InsetInfo in RTL context
[lyx.git] / src / support / lyxlib.h
1 // -*- C++ -*-
2 /**
3  * \file lyxlib.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * A selection of useful system functions made
8  * handy for C++ usage.
9  *
10  * \author Lars Gullik Bjønnes
11  *
12  * Full author contact details are available in file CREDITS.
13  */
14
15 #ifndef LYX_LIB_H
16 #define LYX_LIB_H
17
18 // always include <math.h> (also with MSVC), to avoid compiler specific side effects
19 #include <math.h>
20
21 #ifdef _MSC_VER
22 /// Replacement for C99 round()
23 inline double round(double x)
24 {
25         if (x < 0)
26                 return ceil(x - 0.5);
27         else
28                 return floor(x + 0.5);
29 }
30 #endif
31
32 namespace lyx {
33 namespace support {
34
35 /// FIXME: some point to this hmm ?
36 int kill(int pid, int sig);
37
38 /**
39  * Returns true if var is approximately equal to number with allowed error
40  * of 'error'.
41  *
42  * Usage: if (float_equal(var, number, 0.0001)) { }
43  *
44  * This will check if 'var' is approx. equal to 'number' with error of 1/1000
45  */
46 inline bool float_equal(double var, double number, double error)
47 {
48         return (number - error <= var && var <= number + error);
49 }
50
51 /// round \p x to nearest integer
52 inline int iround(double x)
53 {
54         return static_cast<int>(round(x));
55 }
56
57 } // namespace support
58 } // namespace lyx
59
60 #endif /* LYX_LIB_H */