-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Very small numbers print as Inf.e-324
#615
Comments
I dug in a little bit here: https://stackoverflow.com/a/74131254/190277 but didn't make it all the way to the bottom ... |
Problem appears to be in the function safe_divide_10_to <- function(x, y) { given in R |
It's pretty funny that the source code is safe_divide_10_to <- function(x, y) {
# Computes x / 10^y in a robust way
x / (10^y)
} Did someone mean to implement a robust division by In this particular case the solution to tidyverse/tibble#377 isn't useful, as |
Thanks, good catch. Would Is this a case of comment rot? I don't remember what happened here off the top of my head. |
Yes, that will work. Speed is hardly different (note units are in nanoseconds ...) x <- 4.94e-324
y <- -324
library(microbenchmark)
l10 <- log(10) ## precompute
f1 <- function(x,y) exp(log(x)-y*l10)
f2 <- function(x,y) 10^(log10(x)-y)
all.equal(f1(x,y), f2(x,y))
mb <- microbenchmark(f1(x,y), f2(x,y), times = 10000L)
Unit: nanoseconds
expr min lq mean median uq max neval cld
f1(x, y) 641 671 712.3680 691 721 6222 10000 a
f2(x, y) 661 691 740.3547 711 742 9337 10000 b |
This also worked for me https://stackoverflow.com/a/74132326/6912817 in Windows / Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
|
Reprex:
This looks similar to tidyverse/tibble#377, which was previously closed at d3e1384.
The text was updated successfully, but these errors were encountered: