libc/fixedmatch: Avoid "divide by zero" error

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao 2022-04-22 06:52:11 +08:00 committed by Petro Karashchenko
parent cbdd39b6c9
commit f4d5a23571
1 changed files with 2 additions and 4 deletions

View File

@ -55,7 +55,7 @@ ub16_t ub32sqrtub16(ub32_t a)
xk = (uint64_t)1 << 63;
}
do
while (xk)
{
uint64_t xk1 = (xk + n / xk) >> 1;
@ -66,7 +66,6 @@ ub16_t ub32sqrtub16(ub32_t a)
xk = xk1;
}
while (1);
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^32)' => 'sqrt(a) * 2^16', thus
* 'xk' holds square root of 'a' in ub16_t format.
@ -101,7 +100,7 @@ ub8_t ub16sqrtub8(ub16_t a)
xk = (uint32_t)1 << 31;
}
do
while (xk)
{
uint32_t xk1 = (xk + n / xk) >> 1;
@ -112,7 +111,6 @@ ub8_t ub16sqrtub8(ub16_t a)
xk = xk1;
}
while (1);
/* 'xk' now holds 'sqrt(n)' => 'sqrt(a * 2^16)' => 'sqrt(a) * 2^8', thus
* 'xk' holds square root of 'a' in ub8_t format.