From e992535fc113e6fdabad3649afd16b1b86be2f30 Mon Sep 17 00:00:00 2001 From: Giovanni Harting <539@idlegandalf.com> Date: Wed, 15 Nov 2023 21:57:20 +0100 Subject: [PATCH] limit packet loss --- rtt.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rtt.go b/rtt.go index b8a3bc5..1db080f 100644 --- a/rtt.go +++ b/rtt.go @@ -121,7 +121,7 @@ func (cp *ContinuousPinger) Stats(dSent, dReceive int) (*PingStats, error) { } } ps.AvgRtt = time.Duration(sum / int64(pkgsInArr)) - ps.PacketLoss = math.Min(100, 100-(float64(dReceive)/float64(dSent)*100)) + ps.PacketLoss = math.Min(100, math.Max(100-(float64(dReceive)/float64(dSent)*100), 0)) stdDev, err := stats.StandardDeviation(rttArray) if err != nil { return nil, err