Skip to content

Commit

Permalink
Merge pull request #39 from jamiealquiza/jamie/scale-fix
Browse files Browse the repository at this point in the history
scale func updated to handle all equal input values
  • Loading branch information
jamiealquiza authored May 2, 2018
2 parents e886387 + 4223a84 commit 648c1d0
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion tachymeter.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,5 +294,12 @@ func (h *Histogram) String(s int) string {
// Scale scales the input x with the input-min a0,
// input-max a1, output-min b0, and output-max b1.
func scale(x, a0, a1, b0, b1 float64) float64 {
return (x-a0)/(a1-a0)*(b1-b0) + b0
a, b := x-a0, a1-a0
var c float64
if a == 0 {
c = 0
} else {
c = a / b
}
return c*(b1-b0) + b0
}

0 comments on commit 648c1d0

Please sign in to comment.