diff options
| author | Will Hawkins <[email protected]> | 2022-11-07 18:25:27 -0500 |
|---|---|---|
| committer | Will Hawkins <[email protected]> | 2022-11-07 18:30:47 -0500 |
| commit | 4a0fd25ae07063361a83d5bfda55306eaf3e426e (patch) | |
| tree | 7e95aec3f105b9e7de4d0fe384a0b9bb49baa170 /utilities/utilities.go | |
| parent | f7d143bcf8703c41a39d9b8e7896b6e7468d6fd7 (diff) | |
[Feature] Add a function for determining approximate equality for floats.
Diffstat (limited to 'utilities/utilities.go')
| -rw-r--r-- | utilities/utilities.go | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/utilities/utilities.go b/utilities/utilities.go index 01e2cdd..538889c 100644 --- a/utilities/utilities.go +++ b/utilities/utilities.go @@ -195,3 +195,11 @@ func FilenameAppend(filename, appendage string) string { } return result } + +func ApproximatelyEqual[T float32 | float64](truth T, maybe T, fudge T) bool { + bTruth := float64(truth) + bMaybe := float64(maybe) + bFudge := float64(fudge) + diff := math.Abs((bTruth - bMaybe)) + return diff < bFudge +} |
