Bug 17450 - hist() warns of integer overflow in rare cases
Summary: hist() warns of integer overflow in rare cases
Status: CLOSED FIXED
Alias: None
Product: R
Classification: Unclassified
Component: Misc (show other bugs)
Version: R-devel (trunk)
Hardware: All All
: P5 minor
Assignee: R-core
URL:
Depends on:
Blocks:
 
Reported: 2018-07-31 16:53 UTC by Kevin Ushey
Modified: 2018-08-02 17:47 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Kevin Ushey 2018-07-31 16:53:49 UTC
To reproduce:

   hist(seq(1E6, 1E7))

I see:

   > hist(seq(1E6, 1E7))
   Warning in n * h : NAs produced by integer overflow

My understanding is that this comes from the graphics package; in hist.R#131:

   dens <- counts/(n*h) # use un-fuzzed intervals

But because 'n' and 'h' are both of integer type, their product can overflow in some cases. Would it make sense to coerce each with `as.numeric()` before computing their product?

---

> sessionInfo()
R version 3.5.1 (2018-07-02)
Platform: x86_64-apple-darwin15.6.0 (64-bit)
Running under: macOS High Sierra 10.13.6

Matrix products: default
BLAS: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/3.5/Resources/lib/libRlapack.dylib

locale:
[1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base

loaded via a namespace (and not attached):
[1] compiler_3.5.1
Comment 1 Martin Maechler 2018-07-31 18:39:27 UTC
Yes, coercing h makes sense (and is sufficient). It is used in "double" context also in other places.
I'll commit a patch shortly.

How do you guy detect such border cases ?
Comment 2 Kevin Ushey 2018-07-31 21:06:09 UTC
> How do you guy detect such border cases ?

Our users are very meticulous and inevitably do things that tickle some of the corner cases hiding around R :-)
Comment 3 Martin Maechler 2018-08-01 17:38:40 UTC
Fix committed to R-devel (svn rev 75047) ... to be ported to  'R 3.5.1 patched'  soon after.
Comment 4 Kevin Ushey 2018-08-02 17:47:38 UTC
Thank you, Martin!