To round or not to round… [Software]

posted by ElMaestro  – Belgium?, 2019-07-20 17:59 (389 d 21:13 ago) – Posting: # 20415
Views: 4,251

Hi Hötzi,

» I don’t know which kind of measurements you are comparing.

It stinks but there really is no good solution when you have to compare.
(294.1/1000) == 0.2941
[1] FALSE
(2941/10000) == 0.2941
[1] TRUE


One can read ISO standards and manuals about internal float representation (I tried andfell asleep), but at the end of the day if you need to compare you need to compare and hope for the best. Some numbers just cannot be represented accurately in binary.

If you accept an xyz fraction of error on the comparison then the solution is straightforward, like

Match = function (x,y, relative.tol)
{
 if (y<((1+relative.tol)*x))
  if (y>((1-relative.tol)*x))
    return(T)
 return(F)
}

Match(6, 6.001, 0.01)


Ugly as hell :vomit:, and will not work well if you get into extreme binary representations.

I could be wrong, but...

Best regards,
ElMaestro

"Pass or fail" (D. Potvin et al., 2008)

Complete thread:

Activity
 Admin contact
21,014 posts in 4,380 threads, 1,460 registered users;
online 27 (2 registered, 25 guests [including 21 identified bots]).
Forum time: Thursday 15:13 UTC (Europe/Vienna)

If you obey all the rules,
you will miss all the fun.    Katharine Hepburn

The Bioequivalence and Bioavailability Forum is hosted by
BEBAC Ing. Helmut Schütz
HTML5