1999-10-02 16:21:10 +00:00
|
|
|
// -*- C++ -*-
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* \file lyxlib.h
|
2002-09-25 10:03:41 +00:00
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
* Licence details can be found in the file COPYING.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2002-05-30 02:24:33 +00:00
|
|
|
* A selection of useful system functions made
|
|
|
|
* handy for C++ usage.
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author Lars Gullik Bjønnes
|
2002-09-25 10:03:41 +00:00
|
|
|
*
|
2003-08-23 00:17:00 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
2002-05-30 02:24:33 +00:00
|
|
|
*/
|
1999-10-02 16:21:10 +00:00
|
|
|
|
|
|
|
#ifndef LYX_LIB_H
|
|
|
|
#define LYX_LIB_H
|
|
|
|
|
2016-02-17 20:31:37 +00:00
|
|
|
// always include <math.h> (also with MSVC), to avoid compiler specific side effects
|
|
|
|
#include <math.h>
|
|
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
|
|
/// Replacement for C99 round()
|
|
|
|
inline double round(double x)
|
|
|
|
{
|
|
|
|
if (x < 0)
|
|
|
|
return ceil(x - 0.5);
|
|
|
|
else
|
|
|
|
return floor(x + 0.5);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-01-17 22:42:04 +00:00
|
|
|
namespace lyx {
|
2003-06-30 23:56:22 +00:00
|
|
|
namespace support {
|
2000-10-20 13:13:38 +00:00
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/// FIXME: some point to this hmm ?
|
2001-03-15 18:21:56 +00:00
|
|
|
int kill(int pid, int sig);
|
2001-07-28 12:24:16 +00:00
|
|
|
|
2002-05-30 02:24:33 +00:00
|
|
|
/**
|
|
|
|
* Returns true if var is approximately equal to number with allowed error
|
2001-07-28 12:24:16 +00:00
|
|
|
* of 'error'.
|
|
|
|
*
|
|
|
|
* Usage: if (float_equal(var, number, 0.0001)) { }
|
2002-03-21 17:09:55 +00:00
|
|
|
*
|
2001-07-28 12:24:16 +00:00
|
|
|
* This will check if 'var' is approx. equal to 'number' with error of 1/1000
|
|
|
|
*/
|
2005-01-20 19:30:14 +00:00
|
|
|
inline bool float_equal(double var, double number, double error)
|
2001-07-28 12:24:16 +00:00
|
|
|
{
|
|
|
|
return (number - error <= var && var <= number + error);
|
|
|
|
}
|
|
|
|
|
2016-02-17 20:31:37 +00:00
|
|
|
/// round \p x to nearest integer
|
|
|
|
inline int iround(double x)
|
|
|
|
{
|
|
|
|
return static_cast<int>(round(x));
|
|
|
|
}
|
|
|
|
|
2003-06-30 23:56:22 +00:00
|
|
|
} // namespace support
|
2001-03-15 18:21:56 +00:00
|
|
|
} // namespace lyx
|
2002-12-01 22:59:25 +00:00
|
|
|
|
2000-10-20 13:13:38 +00:00
|
|
|
#endif /* LYX_LIB_H */
|