Consider the following R function
is.sqrt <- function(x, y){ if(x^2 == y) TRUE else FALSE }
which answers whether x is the square ro
You can use the near function from dplyr, it has a built-in tolerance.
near
dplyr
is.sqrt <- function(x, y) { near(x^2, y) } is.sqrt(sqrt(2), 2) > TRUE