From 4223a84a6dd654ff906db283c06f5827beeb7786 Mon Sep 17 00:00:00 2001 From: Jamie Alquiza Date: Wed, 2 May 2018 11:28:21 -0600 Subject: [PATCH] scale func updated to handle all equal input values --- tachymeter.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tachymeter.go b/tachymeter.go index 4a6bcc6..c4c0977 100644 --- a/tachymeter.go +++ b/tachymeter.go @@ -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 }