rd_equal {intervals}R Documentation

Test approximate equality using relative difference

Description

Algorithms in this package need to be able to accurately determine when interval endpoints coincide. If floating point values are used for endpoints, required exact equality is not appropriate, so relative difference is used instead.

Usage

rd_equal(x, y, tolerance = .Machine$double.eps^0.5)

Arguments

x A vector of values to be compared, point-wise, to y.
y A vector fo values of the same length as x.
tolerance Tolerance for establishing approximate equality. The default value is the same one used by all.equal.numeric,

Details

For each component in x and its partner in y, the absolute value of difference is compared to the larger of the two individual absolute values. The values are deemed to be equal if the ratio is less than tolerance. When one or both values are infinite, a simple comparison with == is made; when one or both are NA, a NA is returned.

Value

A logical vector of the same length as x and y.

See Also

See all.equal.numeric for related, though distinct, functionality. Specifically, the comparisons made by all.equal.numeric are relative to the mean absolute value of the target; rd_equal, on the other hand, makes pointwise relative difference comparisons.

Examples

eps <- 1e-5
x <- 1:2
y <- x + c( eps, 0 )
intervals:::rd_equal(x, y)

# The relative difference for all.equal() uses the average across the
# target vector in the denominator, while rd_equal() computes the
# denominator coordinate-wise:

intervals:::rd_equal(x, y, tolerance = eps)
all.equal(x, y, tolerance = eps)

# Handling non-finite values

intervals:::rd_equal(
                     c( .8, .9, NA, Inf, -Inf ),
                     c(  1,  1,  1, Inf,  Inf ),
                     tol = .1
                     )

[Package intervals version 0.9.5 Index]