floating_point_comparisons {roperators}R Documentation

Floating point comparison operators

Description

These are an important set of operators missing from base R. In particular, using == on two non-interger numbers can give unexpected results (see examples.)

See this for details: https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

Usage

x %~=% y

x %>~% y

x %<~% y

Arguments

x

numeric

y

numeric

Author(s)

Ben Wiseman, benjamin.wiseman@kornferry.com

See Also

Other comparisons: comparisons

Examples

 ## Floating point test of equality ####

 # Basic Equality - no roperators:
 (0.1 + 0.1 + 0.1) == 0.3   # FALSE
 # Basic Equality - with roperators:
 (0.1 + 0.1 + 0.1) %~=% 0.3 # TRUE


 # NOTE: for floating point >= and <=
 (0.1 + 0.1 + 0.1) %>=% 0.3 # TRUE
 (0.1 + 0.1 + 0.1) %<=% 0.3 # FALSE

 # Use >~ and <~ for greater/less than or approx equal
 (0.1 + 0.1 + 0.1) %>~% 0.3 # TRUE
 (0.1 + 0.1 + 0.1) %<~% 0.3 # TRUE


[Package roperators version 1.3.14 Index]