Skip to content

Commit

Permalink
nanoduration / nanoduration returns double instead of integer64 (#122)
Browse files Browse the repository at this point in the history
* nanoduration / nanoduration returns double instead of integer64

* Tweak changelog, update NEWS [ci skip]

---------

Co-authored-by: Dirk Eddelbuettel <[email protected]>
  • Loading branch information
lsilvest and eddelbuettel authored May 25, 2024
1 parent dfc4073 commit 0beec0c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
3 changes: 3 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
2024-05-24 Leonardo Silvestri <[email protected]>

* R/nanoduration.R: duration divided by duration returns double
* inst/tinytest/test_nanoduration.R: additional test for the above

* inst/include/nanotime/utilities.hpp: Use interface function Rf_asS4
instead of internal SET_S4_OBJECT
* src/interval.cpp: Change setting of S4 bit before names assigment
Expand Down
2 changes: 1 addition & 1 deletion R/nanoduration.R
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ setMethod("*", c("ANY", "nanoduration"),
##' @rdname nanoduration
setMethod("/", c("nanoduration", "nanoduration"),
function(e1, e2) {
as.integer64(S3Part(e1, strictS3=TRUE) / S3Part(e2, strictS3=TRUE))
S3Part(e1, strictS3=TRUE) / S3Part(e2, strictS3=TRUE)
})
##' @rdname nanoduration
setMethod("/", c("nanoduration", "integer64"),
Expand Down
6 changes: 5 additions & 1 deletion inst/NEWS.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
\newcommand{\ghpr}{\href{https://github.com/eddelbuettel/nanotime/pull/#1}{##1}}
\newcommand{\ghit}{\href{https://github.com/eddelbuettel/nanotime/issues/#1}{##1}}

\section{Changes in version 0.3.8 (2023-07-xx)}{
\section{Changes in version 0.3.8 (2024-xx-xx)}{
\itemize{
\item Time format documentation now has a reference to \pkg{RcppCCTZ}
\item The package no longer sets a default C++ compilation standard (Dirk
Expand All @@ -13,6 +13,10 @@
\ghit{115})
\item The \code{as.Date()} function is now vectorized and can take a TZ
argument (Leonardo and Dirk in \ghpr{119} closing \ghit{118})
\item Use of internal function \code{SET_S4_OBJECT} has been replaced by
API function \code{Rf_asS4} (Leonardo in \ghpr{121} closing \ghit{120})
\item An \code{nanoduration} / \code{nanoduration} expression now returns
a double (Leonardo in \ghpr{122} closing \ghit{117})
}
}

Expand Down
5 changes: 4 additions & 1 deletion inst/tinytest/test_nanoduration.R
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,10 @@ expect_error(1.5 / as.nanoduration("00:01:00"), "invalid operand types")
expect_error(as.nanoduration("1:00:00") / "a", "invalid operand types")

##test_nanoduration_div_nanoduration <- function() {
expect_identical(as.nanoduration(6) / as.nanoduration(2), as.integer64(3))
expect_identical(as.nanoduration(6) / as.nanoduration(2), 3.0)

##test_nanoduration_div_nanoduration <- function() {
expect_identical(as.nanoduration(7) / as.nanoduration(2), 3.5)


## unary
Expand Down

0 comments on commit 0beec0c

Please sign in to comment.