Skip to content

Commit

Permalink
Merge pull request #353 from r-quantities/fix/351
Browse files Browse the repository at this point in the history
remove tolerance from comparisons with logical operators
  • Loading branch information
edzer authored Aug 9, 2023
2 parents 626a41d + 9d3c636 commit a86ee43
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: units
Version: 0.8-2
Version: 0.8-3
Title: Measurement Units for R Vectors
Authors@R: c(person("Edzer", "Pebesma", role = c("aut", "cre"), email = "edzer.pebesma@uni-muenster.de", comment = c(ORCID = "0000-0001-8049-7069")),
person("Thomas", "Mailund", role = "aut", email = "mailund@birc.au.dk"),
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# version 0.8-3

* Remove tolerance from comparisons with logical operators, restoring behavior
changed in previous release; #353 addressing #351

# version 0.8-2

* Names are preserved when doing unit conversions; #305 @billdenney
Expand Down
18 changes: 9 additions & 9 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.71 for units 0.8-2.
# Generated by GNU Autoconf 2.71 for units 0.8-3.
#
# Report bugs to <edzer.pebesma@uni-muenster.de>.
#
Expand Down Expand Up @@ -610,8 +610,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='units'
PACKAGE_TARNAME='units'
PACKAGE_VERSION='0.8-2'
PACKAGE_STRING='units 0.8-2'
PACKAGE_VERSION='0.8-3'
PACKAGE_STRING='units 0.8-3'
PACKAGE_BUGREPORT='edzer.pebesma@uni-muenster.de'
PACKAGE_URL=''

Expand Down Expand Up @@ -1265,7 +1265,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures units 0.8-2 to adapt to many kinds of systems.
\`configure' configures units 0.8-3 to adapt to many kinds of systems.
Usage: $0 [OPTION]... [VAR=VALUE]...
Expand Down Expand Up @@ -1327,7 +1327,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of units 0.8-2:";;
short | recursive ) echo "Configuration of units 0.8-3:";;
esac
cat <<\_ACEOF
Expand Down Expand Up @@ -1416,7 +1416,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
units configure 0.8-2
units configure 0.8-3
generated by GNU Autoconf 2.71
Copyright (C) 2021 Free Software Foundation, Inc.
Expand Down Expand Up @@ -1668,7 +1668,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by units $as_me 0.8-2, which was
It was created by units $as_me 0.8-3, which was
generated by GNU Autoconf 2.71. Invocation command line was
$ $0$ac_configure_args_raw
Expand Down Expand Up @@ -4832,7 +4832,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by units $as_me 0.8-2, which was
This file was extended by units $as_me 0.8-3, which was
generated by GNU Autoconf 2.71. Invocation command line was
CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -4887,7 +4887,7 @@ ac_cs_config_escaped=`printf "%s\n" "$ac_cs_config" | sed "s/^ //; s/'/'\\\\\\\\
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config='$ac_cs_config_escaped'
ac_cs_version="\\
units config.status 0.8-2
units config.status 0.8-3
configured by $0, generated by GNU Autoconf 2.71,
with options \\"\$ac_cs_config\\"
Expand Down
4 changes: 3 additions & 1 deletion src/udunits.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ IntegerVector ud_compare(NumericVector x, NumericVector y,
if (j == y.size())
j = 0;
double diff = x[i] - y[j];
if (x[i] == y[j] || std::abs(diff) < std::numeric_limits<float>::epsilon())
// double lnum = std::abs(x[i]) - std::abs(y[i]) > 0 ? x[i] : y[i];
// double tol = std::abs(lnum) * std::numeric_limits<double>::epsilon();
if (x[i] == y[j]) // || std::abs(diff) < tol)
out[i] = 0;
else if (ISNAN(diff))
out[i] = NA_INTEGER;
Expand Down
9 changes: 6 additions & 3 deletions tests/testthat/test_misc.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,11 +98,14 @@ test_that("set_units works with symbols in character data, and resolves names",
})

test_that("all.equal works", {
expect_false(isTRUE(all.equal(set_units(1, m), 1)))

expect_true(all.equal(set_units(1, m/s), set_units(3.6, km/h)))
expect_true(set_units(1, m/s) == set_units(3.6, km/h))
expect_true(all.equal(set_units(3.6, km/h), set_units(1, m/s)))
expect_true(set_units(3.6, km/h) == set_units(1, m/s))
expect_false(isTRUE(all.equal(set_units(1, m), 1)))

expect_true(set_units(1, m/s) == set_units(3.6, km/h))
expect_false(set_units(3.6, km/h) == set_units(1, m/s)) # see R FAQ 7.31
expect_true(set_units(1e-20, g) < set_units(1e-10, g)) # see #351
})

test_that("seq works", {
Expand Down

0 comments on commit a86ee43

Please sign in to comment.