diff options
author | Ting Shen <phoenixshen@google.com> | 2021-01-25 18:14:36 +0800 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2021-01-27 06:09:46 +0000 |
commit | 2b8e109ef452b5419f64262c895816245b3496f4 (patch) | |
tree | 47238fe0e0db2ad7e7935713709b6428eac13301 /include/math_util.h | |
parent | e9af813c36b7b411bf2a01cbc1b09d5fdec49b8a (diff) | |
download | chrome-ec-2b8e109ef452b5419f64262c895816245b3496f4.tar.gz |
math_util: fix incorrect int_sqrtf implementation
Correct the binary search interval for small x.
The range should be at least [0, sqrt(2 ** 31)] ~= [0, 46341].
Also fixed some corner cases and added unit test for it.
BUG=b:177384512
TEST=1)`watch -n 0.3 ectool motionsense lid_angle`
verify the angle looks reasonable.
2) TEST_LIST_HOST=fp make runhosttests
BRANCH=main
Signed-off-by: Ting Shen <phoenixshen@google.com>
Change-Id: I394fe3a59ac51ec4491a24399848f179c1074b95
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2646041
Tested-by: Ting Shen <phoenixshen@chromium.org>
Reviewed-by: Yilin Yang (kerker) <kerker@chromium.org>
Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Commit-Queue: Ting Shen <phoenixshen@chromium.org>
Diffstat (limited to 'include/math_util.h')
-rw-r--r-- | include/math_util.h | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/include/math_util.h b/include/math_util.h index 266bde6743..b78523de54 100644 --- a/include/math_util.h +++ b/include/math_util.h @@ -136,6 +136,11 @@ static inline int ceil_for(int n, int m) } /** + * Integer square root + */ +int int_sqrtf(fp_inter_t x); + +/** * Square root */ fp_t fp_sqrtf(fp_t a); |