From ebede66b564c851c07e030bf6c5a6756910f17ea Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Sun, 16 Mar 2025 15:29:49 -0500 Subject: [PATCH 1/6] Support conversion of hexidecimal values --- src/integer64.c | 7 ++++++- tests/testthat/test-integer64.R | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/integer64.c b/src/integer64.c index 7c0bbd0..6ee5490 100644 --- a/src/integer64.c +++ b/src/integer64.c @@ -156,7 +156,12 @@ SEXP as_integer64_character(SEXP x_, SEXP ret_){ char * endpointer; for(i=0; i Date: Sun, 16 Mar 2025 17:30:23 -0500 Subject: [PATCH 2/6] Fix handling of negative values and add more tests --- src/integer64.c | 7 ++++++- tests/testthat/test-integer64.R | 17 +++++++++++++++-- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/integer64.c b/src/integer64.c index 6ee5490..5fccac2 100644 --- a/src/integer64.c +++ b/src/integer64.c @@ -157,11 +157,16 @@ SEXP as_integer64_character(SEXP x_, SEXP ret_){ for(i=0; i Date: Sun, 16 Mar 2025 15:56:16 -0700 Subject: [PATCH 3/6] style tweaks --- tests/testthat/test-integer64.R | 34 +++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index 9ed574b..d131309 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -9,22 +9,6 @@ test_that("integer64 coercion to/from other types work", { # to integer64 expect_identical(as.integer64(TRUE), as.integer64(1L)) expect_identical(as.integer64(as.character(1:10)), as.integer64(1:10)) - expect_identical(as.integer64(c("0x1", "0xF")), as.integer64(c(1, 15))) - # Test the first value too large to store in a 32-bit signed integer. - expect_identical(as.integer64(c("0x100000000")), as.integer64(2^32)) - # Test some negative values. - expect_identical(as.integer64(c("-0x0", "-0x1", "-0xF")), as.integer64(c(0, -1, -15))) - # Test mixed positive and negatives - expect_identical(as.integer64(c("-0xA", "0xF")), as.integer64(c(-10, 15))) - # Test the smallest and largest values different from the extreme values of the representation. - # See the documentation for lim.integer64() for more information on the extremes. - expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFE","0x7FFFFFFFFFFFFFFE")), lim.integer64() + (c(1,-1))) - # Test smallest and largest representable values. - expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFF","0x7FFFFFFFFFFFFFFF")), lim.integer64()) - # Test too-small and too-large values: they return the extreme values of the representation. - expect_identical(as.integer64(c("-0x8000000000000000","0x8000000000000000")), lim.integer64()) - # Test that the upper- and lower-case versions work. - expect_identical(as.integer64(c("0xa", "0Xa", "0xA", "0xa")), as.integer64(rep(10, 4))) x = as.integer64(1:10) expect_identical(as.integer64(x), x) @@ -44,6 +28,24 @@ test_that("integer64 coercion to/from other types work", { expect_identical(as.integer64(NA_character_), NA_integer64_) }) +test_that("hex string --> integer64 coercion works (as it does for integer)", { + expect_identical(as.integer64(c("0x1", "0xF")), as.integer64(c(1L, 15L))) + # Test the first value too large to store in a 32-bit signed integer. + expect_identical(as.integer64("0x100000000"), as.integer64(2L^32L)) + # Test some negative values. + expect_identical(as.integer64(c("-0x0", "-0x1", "-0xF")), as.integer64(c(0L, -1L, -15L))) + # Test mixed positive and negatives + expect_identical(as.integer64(c("-0xA", "0xF")), as.integer64(c(-10L, 15L))) + # Test the smallest and largest values different from the extreme values of the representation. + expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFE", "0x7FFFFFFFFFFFFFFE")), lim.integer64() + c(1L, -1L)) + # Test smallest and largest representable values. + expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFF", "0x7FFFFFFFFFFFFFFF")), lim.integer64()) + # not representable in 64 bits --> lim.integer64(), same as non-hex string input + expect_identical(as.integer64(c("-0x8000000000000000", "0x8000000000000000")), lim.integer64()) + # case insensitive + expect_identical(as.integer64(c("0xa", "0Xa", "0xA", "0xa")), as.integer64(rep(10L, 4L))) +}) + test_that("S3 class basics work", { x = as.integer64(1:10) expect_s3_class(x, "integer64") From 6019ed5177bdecb4843cfbd057228dc1b67bbbfa Mon Sep 17 00:00:00 2001 From: Marc Paterno Date: Mon, 17 Mar 2025 08:16:17 -0500 Subject: [PATCH 4/6] Test small decimal negatives and zero --- tests/testthat/test-integer64.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index 9ed574b..9d8af4d 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -8,7 +8,7 @@ test_that("integer64 coercion to/from other types work", { # to integer64 expect_identical(as.integer64(TRUE), as.integer64(1L)) - expect_identical(as.integer64(as.character(1:10)), as.integer64(1:10)) + expect_identical(as.integer64(as.character(-10:10)), as.integer64(-10:10)) expect_identical(as.integer64(c("0x1", "0xF")), as.integer64(c(1, 15))) # Test the first value too large to store in a 32-bit signed integer. expect_identical(as.integer64(c("0x100000000")), as.integer64(2^32)) From c247898d95dd9d8c1a38af4daf85bc60718e3929 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 17 Mar 2025 08:57:51 -0700 Subject: [PATCH 5/6] bad copy-paste --- tests/testthat/test-integer64.R | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index f9d3f89..56cb66e 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -9,23 +9,6 @@ test_that("integer64 coercion to/from other types work", { # to integer64 expect_identical(as.integer64(TRUE), as.integer64(1L)) expect_identical(as.integer64(as.character(-10:10)), as.integer64(-10:10)) - expect_identical(as.integer64(c("0x1", "0xF")), as.integer64(c(1, 15))) - # Test the first value too large to store in a 32-bit signed integer. - expect_identical(as.integer64(c("0x100000000")), as.integer64(2^32)) - # Test some negative values. - expect_identical(as.integer64(c("-0x0", "-0x1", "-0xF")), as.integer64(c(0, -1, -15))) - # Test mixed positive and negatives - expect_identical(as.integer64(c("-0xA", "0xF")), as.integer64(c(-10, 15))) - # Test the smallest and largest values different from the extreme values of the representation. - # See the documentation for lim.integer64() for more information on the extremes. - expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFE","0x7FFFFFFFFFFFFFFE")), lim.integer64() + (c(1,-1))) - # Test smallest and largest representable values. - expect_identical(as.integer64(c("-0x7FFFFFFFFFFFFFFF","0x7FFFFFFFFFFFFFFF")), lim.integer64()) - # Test too-small and too-large values: they return the extreme values of the representation. - expect_identical(as.integer64(c("-0x8000000000000000","0x8000000000000000")), lim.integer64()) - # Test that the upper- and lower-case versions work. - expect_identical(as.integer64(c("0xa", "0Xa", "0xA", "0xa")), as.integer64(rep(10, 4))) - x = as.integer64(1:10) expect_identical(as.integer64(x), x) From 73847bb40c3ebb61ad10aa235ace014b7032a564 Mon Sep 17 00:00:00 2001 From: Michael Chirico Date: Mon, 17 Mar 2025 08:58:58 -0700 Subject: [PATCH 6/6] restore more diff, make another test cover <0 --- tests/testthat/test-integer64.R | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/testthat/test-integer64.R b/tests/testthat/test-integer64.R index 56cb66e..aa4050b 100644 --- a/tests/testthat/test-integer64.R +++ b/tests/testthat/test-integer64.R @@ -9,6 +9,8 @@ test_that("integer64 coercion to/from other types work", { # to integer64 expect_identical(as.integer64(TRUE), as.integer64(1L)) expect_identical(as.integer64(as.character(-10:10)), as.integer64(-10:10)) + expect_identical(as.integer64(as.double(-10:10)), as.integer64(-10:10)) + expect_identical(as.integer64(NULL), as.integer64()) x = as.integer64(1:10) expect_identical(as.integer64(x), x)