Skip to content

Commit

Permalink
fix generating floating point operations
Browse files Browse the repository at this point in the history
  • Loading branch information
sbird committed Jul 7, 2023
1 parent 4a08c16 commit a0d21e1
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions include/fpmath.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ typedef u32 uq4_12_t;
#define UQ_4_12_SHIFT (12)

// Converts a number to Q8.8 fixed-point format
#define Q_8_8(n) ((s16)((n) * 256.0))
#define Q_8_8(n) ((s16)((n) * 256))

// Converts a number to Q4.12 fixed-point format
#define Q_4_12(n) ((q4_12_t)((n) * 4096.0))
#define UQ_4_12(n) ((uq4_12_t)((n) * 4096.0))
#define Q_4_12(n) ((q4_12_t)((n) * 4096))
#define UQ_4_12(n) ((uq4_12_t)((n) * 4096))

// Converts a number to Q24.8 fixed-point format
#define Q_24_8(n) ((s32)((n) * 256.0))
#define Q_24_8(n) ((s32)((n) * 256))

// Converts a Q8.8 fixed-point format number to a regular integer
#define Q_8_8_TO_INT(n) ((s32)((n) / 256))
Expand All @@ -31,8 +31,6 @@ typedef u32 uq4_12_t;
#define Q_4_12_ROUND ((1) << (Q_4_12_SHIFT - 1))
#define UQ_4_12_ROUND ((1) << (UQ_4_12_SHIFT - 1))

#define UQ_4_12_PERCENT(n) (UQ_4_12(n / 100.0))

// Basic arithmetic for fixed point number formats
// Consumers should use encapsulated functions where possible

Expand Down

0 comments on commit a0d21e1

Please sign in to comment.