c - How to do a set union of two double floating point arrays but allowing a tolerance of error of 1 microsecond -


i trying calculate union of 2 arrays containing double floating point values (they timestamps in milliseconds), need allow tolerance of +/- 1 microsecond.

for example: consider 2 values 2 different lists (or arrays) below:

[ref   0 : 1114974059.841] [dut   0 : 1114974059.840] 

there small delta between above 2 numbers of .001 microseconds. when make new union list, shouldn't both appear unique, should counted 1 item, , should have item first list (in example, ref one, ending in 059.841).

more examples of above type:

[ref  21 : 1114974794.562] [dut  18 : 1114974794.560] [ref  22 : 1114974827.840] [dut  19 : 1114974827.840] [ref  23 : 1114974861.121] [dut  20 : 1114974861.120] 

all above should considered one, , hence union list should have 1 item of first list: union list have 3 ref array, , none dut array.

now consider example :

[ref   8 : 1114974328.641] [dut   8 : 1114974361.921] 

here, delta between 2 values in list above quite significant respect microseconds, , comes under .01 micro-seconds, , hence should considered 2 unique items in new union list.

here example above 1 :

[ref  13 : 1114974495.041] [dut  12 : 1114974528.321] [ref  26 : 1114974960.960] [dut  23 : 1114975027.520] [ref  27 : 1114974994.240] [dut  23 : 1114975027.780] 

they should considered unique in new union list.

can me?

i made subroutine allows me detect tolerance this:

unsigned int almostequalrelative(double a, double b, double maxreldiff){     double diff = fabs(a - b);      // calculate difference.     //      if (diff < maxreldiff) {         //printf("\n page hit    [ref: %10.3f] [dut: %10.3f]",a,b);         return 1;     }         //printf("\n page miss   [ref: %10.3f] [dut: %10.3f]",a,b);     return 0;  } 

i give maxreldiff .02.

assuming 2 lists of same size:

unsigned int // size of output array union_list(const double *list1, // first list            const double *list2, // second list            double* ulist,       // output list            unsigned int size)   // size of input list {     unsigned int = 0u, j = 0u ;     for(; < size; ++i, ++j)     {         result = is_near(list1[i], list[2]);         if (result == 1)         {             ulist[j] = list1[i] ;         }         else         {              ulist[j] = list1[i] ;             j += 1 ;             ulist[j] = list2[i];         }     }     return j ; } 

now ulist output array. maximum value can contain size*2 , minimum size. allocate max number of elements. returned value size of output array.

int is_near(double a, double b) {     int result = 1 ;     if (fabs(a - b) >= relative_error)         result = 2 ;     return result ; } 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -