plot/plotter: NewHist(binPoints) panic when a small negative number is used
- Dominant language
- Go
- Stars
- 3k
- Forks
- 201
- PR merge metrics
- No merged PRs in 30d
Description
## What are you trying to do?
I am trying to analyze the distribution of a series of numbers by ``plotter.NewHist``
## What did you do?
Here is a minimal example of the code I used:
```go
func TestA(t *testing.T) {
data := []float64{203.4, -9.223372036854776e+17, 220.4}
_, err := plotter.NewHist(plotter.Values(data), 10)
if err != nil {
fmt.Println(err)
}
}
```
## What did you expect to happen?
some bin are returned and there is no error or panic
## What actually happened?
funcion binPoints panics with following message
panic: 203.4, xmin=-9.223372036854776e+17, xmax=220.4, w=9.223372036854779e+16, bin=10, n=10
## What version of Go and Gonum/plot are you using?
Go 1.23
gonum.org/v1/plot v0.15.0
Also reproduced in
Go 1.20
gonum.org/v1/plot v0.0.0-20190515093506-e2840ee46a6b
## Annotation
When debugging, I find the ``bin`` is set to 10 wrongly. I doubt it is the computing accuracy problem for float64. Maybe ``if x == xmax`` (line 213) should be changed to ``if bin >=n``?
Contributor guide
Assessment
This issue has not been assessed yet.