mirror of
https://github.com/CTCaer/hekate
synced 2024-12-22 03:11:16 +00:00
bdk: utils: add approx. square root calc for u64
This commit is contained in:
parent
ebf0db77ee
commit
ebe7b5a603
2 changed files with 29 additions and 0 deletions
|
@ -75,6 +75,34 @@ char *strcpy_ns(char *dst, char *src)
|
|||
return dst;
|
||||
}
|
||||
|
||||
// Approximate square root finder for a 64-bit number.
|
||||
u64 sqrt64(u64 num)
|
||||
{
|
||||
u64 base = 0;
|
||||
u64 limit = num;
|
||||
u64 square_root = 0;
|
||||
|
||||
while (base <= limit)
|
||||
{
|
||||
u64 tmp_sqrt = (base + limit) / 2;
|
||||
|
||||
if (tmp_sqrt * tmp_sqrt == num) {
|
||||
square_root = tmp_sqrt;
|
||||
break;
|
||||
}
|
||||
|
||||
if (tmp_sqrt * tmp_sqrt < num)
|
||||
{
|
||||
square_root = base;
|
||||
base = tmp_sqrt + 1;
|
||||
}
|
||||
else
|
||||
limit = tmp_sqrt - 1;
|
||||
}
|
||||
|
||||
return square_root;
|
||||
}
|
||||
|
||||
u32 get_tmr_s()
|
||||
{
|
||||
return RTC(APBDEV_RTC_SECONDS);
|
||||
|
|
|
@ -84,6 +84,7 @@ typedef struct _nyx_storage_t
|
|||
u8 bit_count(u32 val);
|
||||
u32 bit_count_mask(u8 bits);
|
||||
char *strcpy_ns(char *dst, char *src);
|
||||
u64 sqrt64(u64 num);
|
||||
|
||||
void exec_cfg(u32 *base, const cfg_op_t *ops, u32 num_ops);
|
||||
u32 crc32_calc(u32 crc, const u8 *buf, u32 len);
|
||||
|
|
Loading…
Reference in a new issue