From be12d0f3ae0b107810881b2fad48a02ce7dd2984 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Thu, 11 Apr 2024 23:00:20 -0700 Subject: [PATCH 1/4] allow numeric rounding to be 3...7 --- src/forder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forder.c b/src/forder.c index c9063782b..dbc0ce828 100644 --- a/src/forder.c +++ b/src/forder.c @@ -367,7 +367,7 @@ SEXP setNumericRounding(SEXP droundArg) // init.c has initial call with default of 2 { if (!isInteger(droundArg) || LENGTH(droundArg)!=1) error(_("Must an integer or numeric vector length 1")); - if (INTEGER(droundArg)[0] < 0 || INTEGER(droundArg)[0] > 2) error(_("Must be 2, 1 or 0")); + if (INTEGER(droundArg)[0] < 0 || INTEGER(droundArg)[0] > 7) error(_("Must be a number of bytes between 0 and 7")); dround = INTEGER(droundArg)[0]; dmask = dround ? 1 << (8*dround-1) : 0; return R_NilValue; From 42abeab875496b83e5a8034c8ed5ea4c56bd9420 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 6 May 2024 21:43:02 -0700 Subject: [PATCH 2/4] NEWS --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 9163d9eb3..5ac2ed99e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -42,6 +42,8 @@ 13. `dcast`gains `value.var.in.dots`, `value.var.in.LHSdots` and `value.var.in.RHSdots` arguments, [#5824](https://github.com/Rdatatable/data.table/issues/5824). This allows the `value.var` variable(s) in `dcast` to be represented by `...` in the formula (if not otherwise mentioned). Thanks to @iago-pssjd for the report and PR. +14. `setNumericRounding()` numbers 0 to 7, instead of only 0 to 2, [#1898](https://github.com/Rdatatable/data.table/issues/1898). + ## BUG FIXES 1. `unique()` returns a copy the case when `nrows(x) <= 1` instead of a mutable alias, [#5932](https://github.com/Rdatatable/data.table/pull/5932). This is consistent with existing `unique()` behavior when the input has no duplicates but more than one row. Thanks to @brookslogan for the report and @dshemetov for the fix. From a083c99e24895a69f083be10074e256595bb9bb0 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 6 May 2024 21:45:05 -0700 Subject: [PATCH 3/4] man --- man/setNumericRounding.Rd | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/man/setNumericRounding.Rd b/man/setNumericRounding.Rd index f9e00de27..e6dc06e5c 100644 --- a/man/setNumericRounding.Rd +++ b/man/setNumericRounding.Rd @@ -3,7 +3,7 @@ \alias{getNumericRounding} \title{ Change or turn off numeric rounding } \description{ -Change rounding to 0, 1 or 2 bytes when joining, grouping or ordering numeric +Change rounding to 0, 1, ..., or 7 bytes when joining, grouping or ordering numeric (i.e. double, POSIXct) columns. } \usage{ @@ -11,7 +11,7 @@ setNumericRounding(x) getNumericRounding() } \arguments{ - \item{x}{ integer or numeric vector: 0 (default), 1 or 2 byte rounding } + \item{x}{ integer or numeric vector: 0 (default), up to 7 bytes rounding } } \details{ Computers cannot represent some floating point numbers (such as 0.6) @@ -19,7 +19,7 @@ precisely, using base 2. This leads to unexpected behaviour when joining or grouping columns of type 'numeric'; i.e. 'double', see example below. In cases where this is undesirable, data.table allows rounding such data up to approximately 11 significant figures which is plenty of digits for many cases. -This is achieved by rounding the last 2 bytes off the significand. Other possible +This is achieved by rounding the last 2 bytes off the significand. Other common values are 1 byte rounding, or no rounding (full precision, default). It is bytes rather than bits because it is tied in with the radix sort @@ -33,7 +33,7 @@ precision). } \value{ \code{setNumericRounding} returns no value; the new value is applied. -\code{getNumericRounding} returns the current value: 0, 1 or 2. +\code{getNumericRounding} returns the current value: an integer from 0 to 7. } \seealso{ \code{\link{datatable-optimize}}\cr From 7e0c88febee1cacaffacdf984c3ea87fb0e22237 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 6 May 2024 22:17:09 -0700 Subject: [PATCH 4/4] correct comment --- src/forder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/forder.c b/src/forder.c index 5b16cfddb..ab44e4ad5 100644 --- a/src/forder.c +++ b/src/forder.c @@ -1398,7 +1398,7 @@ SEXP isOrderedSubset(SEXP x, SEXP nrowArg) } SEXP binary(SEXP x) -// base::intToBits is close, but why does that print the result as "00 00 00 00" (raw) rather than ("0000") bits? Seems odd. +// base::numToBits is close, but why does that print the result as "00 00 00 00" (raw) rather than ("0000") bits? Seems odd. { char buffer[69]; int j;