-
Notifications
You must be signed in to change notification settings - Fork 76
/
api_comp.R
41 lines (40 loc) · 1.2 KB
/
api_comp.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#' @title Comparison functions
#' @noRd
#'
#' @author Rolf Simoes, \email{rolf.simoes@@inpe.br}
#' @author Felipe Carvalho, \email{felipe.carvalho@@inpe.br}
#'
#' @description
#' Functions to compare two numeric vectors using tolerance parameter.
#'
#' @param x,y a numeric value to compare.
#' @param tolerance a positive numeric value.
#' Default is 0 (exact comparison).
NULL
#' @title Compare if `x` is equal to `y` considering a tolerance
#' @noRd
#' @returns A logical value
.is_eq <- function(x, y, tolerance = 0) {
.check_set_caller(".is_eq")
.check_that(tolerance >= 0)
# Compute result and return
all(abs(x - y) <= tolerance[[1]])
}
#' @title Compare if `x` is less than `y` considering a tolerance
#' @noRd
#' @returns A logical value
.is_lt <- function(x, y, tolerance = 0) {
.check_set_caller(".is_lt")
.check_that(tolerance >= 0)
# Compute result and return
all(abs(y - x) > tolerance[[1]])
}
#' @title Compare if `x` is greater than `y` considering a tolerance
#' @noRd
#' @returns A logical value
.is_gt <- function(x, y, tolerance = 0) {
.check_set_caller(".is_gt")
.check_that(tolerance >= 0)
# Compute result and return
all(abs(x - y) > tolerance[[1]])
}