psolymos / intrval

Relational Operators for Intervals
41 stars 4 forks source link

floating point number comparisons #17

Open achubaty opened 1 month ago

achubaty commented 1 month ago

This is a useful package, I'm sad I hadn't started using it sooner!

Have you considered using more robust comparisons to deal with floating point number problems? See below.

> x1 <- 0.5 - 0.3
> x2 <- 0.3 - 0.1
> 
> x1 %[]% c(0.2, 0.6)
[1] TRUE
> x2 %[]% c(0.2, 0.6)
[1] FALSE

My fpCompare package deals with this for the basic relational operators, but having equivalent functionality to test intervals/ranges may be useful. Although, I recognize that this kind of change may break backwards compatibility / reproducibility without a mechanism (package option?) to use the alternate behaviour.

psolymos commented 1 month ago

@achubaty thanks for raising this issue. This is indeed a problem.

If I import the operators from fpCompare, and setting an option to intrval.use_fpCompare=FALSE for backwards compatibility. When this option is set to TRUE, I would use the fpCompare functions inside the internals with the set fpCompare.tolerance option.