0

I am testing the equivalence of two numeric classes, however when the values being compared are a value of 1 or less R returns False, see console output

As long as the comparison between the value in loadograph and the value in pulse_endTime are greater than 1, things work, however less than one FALSE is returned. Could it be the way the round function was used here?

loadograph$Time<-round(loadograph$Time, 2); pulse_endTime<-round(pulse_endTime, 2)

Any help is appreciated

ruggntub
  • 95
  • 5
  • 1
    Welcome to StackOverflow, please refer to stackoverflow.com/conduct Don't post your code as Photo, write it. Also, Try using `=` instead of `==` – Alaleh Apr 11 '21 at 02:31
  • The `==` sing is a logical comparator. When you call x==y, it returns true if x is equal to y, or false if not – GuedesBF Apr 11 '21 at 02:42
  • 1
    You cannot compare floating point (decimal numbers) for exact equality. See [R FAQ 7.31: Why doesn’t R think these numbers are equal?](https://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-doesn_0027t-R-think-these-numbers-are-equal_003f). See also `?all.equal`. – dcarlson Apr 11 '21 at 02:55
  • Other good links: https://stackoverflow.com/questions/9508518/why-are-these-numbers-not-equal and https://stackoverflow.com/questions/588004/is-floating-point-math-broken. This is not unique to R, it is a fundamental limitation when using constrained bytes to store floating-point numbers, typically implemented using [IEEE-754](https://en.wikipedia.org/wiki/IEEE_754). – r2evans Apr 11 '21 at 03:03
  • Your best option is to see if the absolute-difference is smaller than a threshold. For instance, `abs(loadograph$Time - pulse_endTime[2] - 0.92) < 1e-8`. (The use of `1e-8` is contextual, you may only need `1e-5` or perhaps need even smaller, but don't get too close to `.Machine$neg.eps`.) – r2evans Apr 11 '21 at 03:06

0 Answers0