From b15c99f695a25df05a29cde055e4bd014778d69a Mon Sep 17 00:00:00 2001 From: Will Charczuk Date: Wed, 13 Jul 2016 15:46:51 -0700 Subject: [PATCH] pct diff function --- util.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/util.go b/util.go index 3e18a64..4fefa5c 100644 --- a/util.go +++ b/util.go @@ -135,3 +135,9 @@ func Seq(start, end float64, steps ...float64) []float64 { } return values } + +// PercentageDifference computes the percentage difference between two values. +// The formula is (v2-v1)/v1. +func PercentageDifference(v1, v2 float64) float64 { + return (v2 - v1) / v1 +}