Package list golang-github-beorn7-perks / 1ac20f1
Fix off-by-one error for small sample sizes I reconsidered my previous fix, and replaced rounding to the nearest integer with rounding up. Example: Given 5 observations [1, 2, 3, 4, 5], the ranges of percentiles would be as follows: - Rounding Down (original implementation) 1: 0.0 incl. - 0.4 excl. 2: 0.4 incl. - 0.6 excl. 3: 0.6 incl. - 0.8 excl. 4: 0.8 incl. - 1.0 excl. 5: 1.0 exact value - Rounding to Nearest Integer (my first commit) 1: 0.0 incl. - 0.3 excl. 2: 0.3 incl. - 0.5 excl. 3: 0.5 incl. - 0.7 excl. 4: 0.7 incl. - 0.9 excl. 5: 0.9 incl. - 1.0 incl. - Rounding Up (my second commit) 1: 0.0 incl. - 0.2 incl. 2: 0.2 excl. - 0.4 incl. 3: 0.4 excl. - 0.6 incl. 4: 0.6 excl. - 0.8 incl. 5: 0.8 excl. - 1.0 incl. Fabian Stäber 5 years ago
1 changed file(s) with 1 addition(s) and 1 deletion(s). Raw diff Collapse all Expand all
132132 if l == 0 {
133133 return 0
134134 }
135 i := int(float64(l) * q + 0.5) // Add 0.5 because casting float to int always rounds down.
135 i := int(math.Ceil(float64(l) * q))
136136 if i > 0 {
137137 i -= 1
138138 }