Skip to content

Instantly share code, notes, and snippets.

@MurageKibicho
Created March 19, 2025 12:11
Show Gist options
  • Save MurageKibicho/452d19b37e6d12c1486c6fc281852e76 to your computer and use it in GitHub Desktop.
Save MurageKibicho/452d19b37e6d12c1486c6fc281852e76 to your computer and use it in GitHub Desktop.
FixedPoint
// Online C compiler to run C program online
#include <stdio.h>
#include <stdint.h>
typedef int64_t fixedpt;
#define FIXEDPT_BITS 32
#define FIXEDPT_WBITS 24
#define FIXEDPT_FBITS (FIXEDPT_BITS - FIXEDPT_WBITS)
#define FIXEDPT_ONE ((fixedpt)((fixedpt)1 << FIXEDPT_FBITS))
#define fixedpt_rconst(R) ((fixedpt)((R) * FIXEDPT_ONE + ((R) >= 0 ? 0.5 : -0.5)))
int main() {
fixedpt a = fixedpt_rconst(-4545.8);
printf("%d\n", a);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment