Skip to content

Commit

Permalink
Merge pull request #13 from eddelbuettel/bugfix/issue12
Browse files Browse the repository at this point in the history
fix for formating precision loss (closes #12)
  • Loading branch information
eddelbuettel committed Jan 31, 2017
2 parents c1110d5 + b5c863f commit 72371b3
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
@@ -1,3 +1,8 @@
2017-01-30 Dirk Eddelbuettel <edd@debian.org>

* R/nanotime.R (format.nanotime): Saver transformation to double
(index2char.nanotime): Idem

2017-01-29 Dirk Eddelbuettel <edd@debian.org>

* R/nanotime.R: Additional documentation section on default output
Expand Down
14 changes: 8 additions & 6 deletions R/nanotime.R
Expand Up @@ -146,16 +146,18 @@ format.nanotime <- function(x,
...) {
fmt <- getOption("nanotimeFormat", default="%Y-%m-%dT%H:%M:%E9S%Ez")
tz <- getOption("nanotimeTz", default="UTC")
secs <- trunc(as.double(x/1e9))
nanos <- as.double(x - secs*1e9)
RcppCCTZ::formatDouble(secs, nanos, fmt=fmt, tgttzstr=tz)
bigint <- as.integer64(x)
secs <- as.integer64(bigint / as.integer64(1000000000))
nanos <- bigint - secs * as.integer64(1000000000)
RcppCCTZ::formatDouble(as.double(secs), as.double(nanos), fmt=fmt, tgttzstr=tz)
}

##' @rdname nanotime
index2char.nanotime <- function(x, frequency = NULL, ...) {
secs <- trunc(as.double(x/1e9))
nanos <- as.double(x - secs*1e9)
RcppCCTZ::formatDouble(secs, nanos,
bigint <- as.integer64(x)
secs <- as.integer64(bigint / as.integer64(1000000000))
nanos <- bigint - secs * as.integer64(1000000000)
RcppCCTZ::formatDouble(as.double(secs), as.double(nanos),
fmt=getOption("nanotimeFormat", default="%Y-%m-%dT%H:%M:%E*S%Ez"),
tgttzstr=getOption("nanotimeTz", default="UTC"))
}
Expand Down
2 changes: 2 additions & 0 deletions inst/NEWS.Rd
Expand Up @@ -11,6 +11,8 @@
and a new new converter \code{as.integer64} was added.
\item Several 'Ops' method are now explicitly defined allowing
casting of results (rather than falling back on bit64 behaviour)
\item The format routine is now more careful about not loosing
precision (\ghit{12})
}
}

Expand Down

0 comments on commit 72371b3

Please sign in to comment.