Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#786 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@SashaMIT 已經在處理了。

開始於 2026年10月11日。

  • #807 來自 @SashaMIT —— 未關閉

評估

難度
3/5
預估耗時
1-2 天
新手友好度
55/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
停滯
技術堆疊
go

研究方向

從 plotter.NewHist 和 binPoints 函式開始,著重檢查第 213 行附近的條件,以及報告中包含一個小負值的最小範例。在報告所使用的 Go 和 Gonum/plot 版本下執行該範例,接著確認相同的輸入會回傳 bins 而不會引發 panic,且此行為已由回歸測試涵蓋。

由索引模型根據 Issue 內容生成。

描述

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:

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?

主要語言
Go
星號
3k
分支
202
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

gonum/plot 的其他 Issue

查看 gonum/plot 的全部 Issue

相似的 Issue

更多 Go Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。