go.charczuk.com@v0.0.0-20240327042549-bc490516bd1a/sdk/mathutil/percent_change.go (about) 1 /* 2 3 Copyright (c) 2024 - Present. Will Charczuk. All rights reserved. 4 Use of this source code is governed by a MIT license that can be found in the LICENSE file at the root of the repository. 5 6 */ 7 8 package mathutil 9 10 import "math" 11 12 // PercentChange returns the percent change of two floats. 13 func PercentChange(x1, x2 float64) float64 { 14 if x1 == 0 { 15 return math.Inf(1) 16 } 17 return (x2 - x1) / x1 18 }