BucketedTimeSeries: fix type converison issues computing avg()
authorAdam Simpkins <simpkins@fb.com>
Mon, 20 Aug 2012 21:58:25 +0000 (14:58 -0700)
committerTudor Bosman <tudorb@fb.com>
Sun, 26 Aug 2012 18:13:53 +0000 (11:13 -0700)
commit14223eae3f3cc0059f2d129ceec84b48506a6434
tree96803cef00e733d18b43c3d9df4dad0cee5b486f
parent4f802227dd2f0faf82006dca10189e4af25699fa
BucketedTimeSeries: fix type converison issues computing avg()

Summary:
D527040 had a bug in the code to compute the average: it incorrectly
performed unsigned division when ValueType was a signed integer type.
As a result, the average was reported incorrectly for stats with
negative values.

This makes the average code more intelligent when handling type
conversions: if the caller wants a floating point value, or if the input
type is floating point, floating point division is always returned.
Otherwise, if the input is a signed type, signed integer division is
performed.  Otherwise, unsigned integer division is performed.

Test Plan: beholdunittests

Reviewed By: lars@fb.com

FB internal diff: D553583
folly/detail/Stats.h
folly/stats/BucketedTimeSeries-defs.h
folly/test/TimeseriesTest.cpp