github.com/blend/go-sdk@v1.20220411.3/mathutil/percent_difference.go (about)

     1  /*
     2  
     3  Copyright (c) 2022 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package mathutil
     9  
    10  // PercentDifference computes the percentage difference between two values.
    11  // The formula is (v2-v1)/v1.
    12  func PercentDifference(v1, v2 float64) float64 {
    13  	if v1 == 0 {
    14  		return 0
    15  	}
    16  	return (v2 - v1) / v1
    17  }