gonum / gonum/plot

plot/plotter: NewHist(binPoints) panic when a small negative number is used

Aperta
#786 7 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
3k
Fork
201
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

## 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``?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

Start at plotter.NewHist and the binPoints function, focusing on the condition around line 213 and the reported minimal example with a small negative value. Run the example under the reported Go and Gonum/plot versions, then verify that the same input returns bins without panicking and that the behavior is covered by a regression test.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
go
Ambito
data-visualization
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
55/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.