My understanding is that go fmt is supposed to produce code that is readable and consistently formatted. However I'm not finding this to be the case.
I typed in the commented code and go fmt returned the uncommented code. Why did it collapse 0.5*(y3-y0)
, but not 0.5 * (y2 - y0)
? How is that consistent? And, IMO, the return line with nearly every space collapsed out is a readability disaster.
Is the inconsistency a bug? Is there a way to get go fmt to leave some lines (like the return line) alone?
func cubicInterpolate(x, y0, y1, y2, y3 float64) float64 {
// 4-point, 3rd-order Hermite (x-form)
// c0 := y1
// c1 := 0.5 * (y2 - y0)
// c2 := y0 - 2.5 * y1 + 2. * y2 - 0.5 * y3
// c3 := 1.5 * (y1 - y2) + 0.5 * (y3 - y0)
//
// return ((c3 * x + c2) * x + c1) * x + c0
c0 := y1
c1 := 0.5 * (y2 - y0)
c2 := y0 - 2.5*y1 + 2.*y2 - 0.5*y3
c3 := 1.5*(y1-y2) + 0.5*(y3-y0)
return ((c3*x+c2)*x+c1)*x + c0
}