Last active
May 9, 2024 21:56
-
-
Save victorfeitosa/61ed113fdd0cd24f79b596f9def100de to your computer and use it in GitHub Desktop.
Float point numbers to Fixed number representation
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
#include <stdio.h> | |
typedef int Fixed; | |
#define FRACT_BITS 16 | |
#define FRACT_BITS_D2 8 | |
#define FIXED_ONE (1 << FRACT_BITS) | |
#define INT2FIXED(x) ((x) << FRACT_BITS) | |
#define FLOAT2FIXED(x) ((int)((x) * (1 << FRACT_BITS))) | |
#define FIXED2INT(x) ((x) >> FRACT_BITS) | |
#define FIXED2DOUBLE(x) (((double)(x)) / (1 << FRACT_BITS)) | |
#define MULT(x, y) ( ((x) >> FRACT_BITS_D2) * ((y)>> FRACT_BITS_D2) ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment