A check for (a + b) / 2
- Dominant language
- Java
- Stars
- 7.2k
- Forks
- 820
- Avg merge
- 5h 9m
- Merged PRs (30d)
- 50
Description
_[Original issue](https://code.google.com/p/error-prone/issues/detail?id=116) created by **kevinb@google.com** on 2013-04-04 at 03:45 PM_
---
Fact: _some_ percentage of all occurrences of "(a + b) / 2" out there are bugs, or bugs waiting to happen.
(http://googleresearch.blogspot.com/2006/06/extra-extra-read-all-about-it-nearly.html)
Unfortunately, there's no reasonable fix we can suggest that is guaranteed to work for _all_ possible values of a and b... except Guava's IntMath.mean(a, b) / LongMath.mean(a, b) methods.
If there is ever a place in error-prone for "checks for which the fix _requires_ Guava", then it might be worth having a check that forces users of "(a + b) / 2" to change to use mean(). Most of those users probably weren't vulnerable to the bug, but we can't tell which they are.
If we don't do this, we'll probably just have to give up on ever catching that bug, and we will sadly probably give up on these Guava methods entirely, because literally NO ONE is using them (why would they? They already know how to get the mean of two numbers!).
Contributor guide
Assessment
This issue has not been assessed yet.