1.1 --- a/ucx/comparator.c Wed Feb 27 10:35:42 2013 +0100 1.2 +++ b/ucx/comparator.c Wed Feb 27 10:57:40 2013 +0100 1.3 @@ -1,4 +1,5 @@ 1.4 #include "comparator.h" 1.5 +#include "math.h" 1.6 1.7 int ucx_strcmp(void *s1, void *s2, void *data) { 1.8 return strcmp((char*)s1, (char*)s2); 1.9 @@ -18,6 +19,28 @@ 1.10 } 1.11 } 1.12 1.13 +int ucx_floatcmp(void *f1, void *f2, void *epsilon) { 1.14 + float a = *((float*) f1); 1.15 + float b = *((float*) f2); 1.16 + float e = !epsilon ? 1e-6f : *((float*)epsilon); 1.17 + if (fabsf(a - b) < e) { 1.18 + return 0; 1.19 + } else { 1.20 + return a < b ? -1 : 1; 1.21 + } 1.22 +} 1.23 + 1.24 +int ucx_doublecmp(void *d1, void *d2, void *epsilon) { 1.25 + double a = *((float*) d1); 1.26 + double b = *((float*) d2); 1.27 + double e = !epsilon ? 1e-14 : *((double*)epsilon); 1.28 + if (fabs(a - b) < e) { 1.29 + return 0; 1.30 + } else { 1.31 + return a < b ? -1 : 1; 1.32 + } 1.33 +} 1.34 + 1.35 int ucx_ptrcmp(void *ptr1, void *ptr2, void *data) { 1.36 if (ptr1 == ptr2) { 1.37 return 0;