Created
October 15, 2019 16:25
-
-
Save maximevince/5bc7d485f3fa58ae433473ac5c90cca8 to your computer and use it in GitHub Desktop.
integer sqrt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Simple SQRT calculation | |
* NOTE: result fits within uint16_t (of course) | |
*/ | |
uint32_t sqrt_int32(uint32_t x) | |
{ | |
uint32_t res = 0; | |
uint32_t add = 0x8000; | |
uint32_t temp; | |
uint8_t i; | |
for(i=0; i<16; i++) { | |
temp = res | add; | |
if (x>= (temp*temp)) { | |
res = temp; | |
} | |
add>>=1; | |
} | |
return res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment