Skip to content

Instantly share code, notes, and snippets.

@esromneb
Created September 14, 2022 10:34
Show Gist options
  • Save esromneb/de888391debb482df898e16d6aa0d19c to your computer and use it in GitHub Desktop.
Save esromneb/de888391debb482df898e16d6aa0d19c to your computer and use it in GitHub Desktop.
ffo_lut as a function not a LUT
// https://stackoverflow.com/questions/25585066/removing-slow-int64-division-from-fixed-point-atan2-approximation
uint8_t ffo_lut(const int i) {
if(i <= 1) {
return i;
}
if( i <= 3) {
return 2;
}
if( i < 8) {
return 3;
}
if( i < 16) {
return 4;
}
if( i < 32) {
return 5;
}
if( i < 64) {
return 6;
}
if( i < 128) {
return 7;
}
if( i < 256) {
return 8;
}
if( i < 512) {
return 9;
}
if( i < 1024) {
return 10;
}
if( i < 2048) {
return 11;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment