This repository has been archived by the owner on Jun 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
257 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
Copyright © 2021 Opsani <[email protected]> | ||
This file is part of https://github.com/opsani/opsani-ignite | ||
*/ | ||
|
||
package math | ||
|
||
import ( | ||
m "math" | ||
) | ||
|
||
func Min(samples ...float64) float64 { | ||
min := m.NaN() | ||
for _, val := range samples { | ||
if m.IsNaN(val) || m.IsInf(val, 0) { | ||
continue | ||
} | ||
if m.IsNaN(min) || val < min { | ||
min = val | ||
} | ||
} | ||
return min // will return NaN for empty slice or slice that has no valid values | ||
} | ||
|
||
func Sum(samples ...float64) float64 { | ||
total := 0.0 | ||
for _, val := range samples { | ||
if m.IsNaN(val) || m.IsInf(val, 0) { | ||
continue | ||
} | ||
total += val | ||
} | ||
return total | ||
} | ||
|
||
func Avg(samples ...float64) float64 { | ||
total := 0.0 | ||
count := 0 | ||
for _, val := range samples { | ||
if m.IsNaN(val) || m.IsInf(val, 0) { | ||
continue | ||
} | ||
total += val | ||
count += 1 | ||
} | ||
|
||
if count == 0 { | ||
return 0.0 | ||
} | ||
return total / float64(len(samples)) | ||
} |
Oops, something went wrong.