1#' Compare two numeric vectors
2#'
3#' This is a safe way of comparing if two vectors of floating point numbers
4#' are (pairwise) equal.  This is safer than using `==`, because it has
5#' a built in tolerance
6#'
7#' @param x,y Numeric vectors to compare
8#' @param tol Tolerance of comparison.
9#' @export
10#' @examples
11#' sqrt(2) ^ 2 == 2
12#' near(sqrt(2) ^ 2, 2)
13near <- function(x, y, tol = .Machine$double.eps^0.5) {
14  abs(x - y) < tol
15}
16