Skip to content
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

[bugfix] overflow when calculating stdDev #130

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ type Pinger struct {
maxRtt time.Duration
avgRtt time.Duration
stdDevRtt time.Duration
stddevm2 time.Duration
stddevm2 float64
statsMu sync.RWMutex

// If true, keep a record of rtts of all received packets.
Expand Down Expand Up @@ -340,9 +340,9 @@ func (p *Pinger) updateStatistics(pkt *Packet) {
delta := pkt.Rtt - p.avgRtt
p.avgRtt += delta / pktCount
delta2 := pkt.Rtt - p.avgRtt
p.stddevm2 += delta * delta2
p.stddevm2 += float64(delta) * float64(delta2)

p.stdDevRtt = time.Duration(math.Sqrt(float64(p.stddevm2 / pktCount)))
p.stdDevRtt = time.Duration(math.Sqrt(p.stddevm2 / float64(pktCount)))
}

// SetIPAddr sets the ip address of the target host.
Expand Down