all_equal: Are all values of x nearly equal (within a tolerance) to all...

View source: R/all_equal.R

all_equalR Documentation

Are all values of x nearly equal (within a tolerance) to all values of y?

Description

A memory-efficient alternative to all.equal.numeric().

Usage

all_equal(x, y, tol = get_tolerance(), na.rm = FALSE)

Arguments

x

A double vector.

y

A double vector.

tol

A double vector of tolerances.

na.rm

Should NA values be ignored? Default is FALSE.

Details

all_equal compares each pair of double-precision floating point numbers in the same way as double_equal. If any numbers differ, the algorithm breaks immediately, which can offer significant speed when there are differences at the start of a vector. All arguments are recycled except na.rm.

Value

A logical vector of length 1.

The result should match all(double_equal(x, y)), including the way NA values are handled.

Examples

library(cppdoubles)
library(bench)
x <- seq(0, 1, 0.2)
y <- sqrt(x)^2

all_equal(x, y)

# Comparison to all.equal
z <- runif(10^4, 1, 100)
ones <- rep(1, length(z))
mark(base = isTRUE(all.equal(z, z)),
            cppdoubles = all_equal(z, z),
            iterations = 100)
mark(base = isTRUE(all.equal(z, ones)),
            cppdoubles = all_equal(z, ones),
            iterations = 100)


cppdoubles documentation built on June 9, 2025, 5:09 p.m.