diff options
Diffstat (limited to 'tools.h')
-rw-r--r-- | tools.h | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -4,7 +4,7 @@ * See the main source file 'vdr.c' for copyright information and * how to reach the author. * - * $Id: tools.h 2.2 2009/04/14 20:41:39 kls Exp $ + * $Id: tools.h 2.3 2009/12/06 11:24:12 kls Exp $ */ #ifndef __TOOLS_H @@ -13,7 +13,9 @@ #include <dirent.h> #include <errno.h> #include <fcntl.h> +#include <float.h> #include <iconv.h> +#include <math.h> #include <poll.h> #include <stddef.h> #include <stdint.h> @@ -60,7 +62,7 @@ void syslog_with_tid(int priority, const char *format, ...) __attribute__ ((form int BCD2INT(int x); // Unfortunately there are no platform independent macros for unaligned -// access. so we do it this way: +// access, so we do it this way: template<class T> inline T get_unaligned(T *p) { @@ -74,6 +76,14 @@ template<class T> inline void put_unaligned(unsigned int v, T* p) ((s *)p)->v = v; } +// Comparing doubles for equality is unsafe, but unfortunately we can't +// overwrite operator==(double, double), so this will have to do: + +inline bool DoubleEqual(double a, double b) +{ + return fabs(a - b) <= DBL_EPSILON; +} + // When handling strings that might contain UTF-8 characters, it may be necessary // to process a "symbol" that consists of several actual character bytes. The // following functions allow transparently accessing a "char *" string without |