diff options
| author | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-25 17:37:40 -0300 |
|---|---|---|
| committer | Uneven Prankster <unevenprankster@protonmail.com> | 2023-07-25 17:37:40 -0300 |
| commit | 593e8163a2442546a459d98d8febcaa9c2cbceb9 (patch) | |
| tree | 713cf2bc250a358ac7ff480ae4aeb443a0c5b837 /src/config.h | |
| parent | 6f4930e920b3f368d0fcb9acfd2824095b101681 (diff) | |
Added explanation for Fixed-point usage, + a useful macro
Diffstat (limited to 'src/config.h')
| -rw-r--r-- | src/config.h | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/config.h b/src/config.h index 5099409..18dc414 100644 --- a/src/config.h +++ b/src/config.h @@ -9,12 +9,28 @@ typedef unsigned long long u64; typedef float f32; typedef double f64; +/* +You may be wondering "why fixed point values???", and that's simple +Floating Point was a mistake and has caused great suffering to countless. +Time-keeping is specially burdened. Nobody should ever keep track of time +with float values. Variable precision can and WILL throw off calculations +no matter how much of a NERD you are. + +What I did was to just leverage the support for floats in order to make most +things simply take them (that's what everyone expects) then convert them to +fixed point for precise operations. + +They can still be happily used for other things, specially inside shaders. +But don't @ me. +*/ + // 24.8 format typedef i32 fx32; #define FIXED_POINT_BITS 8 #define FIXED_POINT_ONE (1 << FIXED_POINT_BITS) #define TO_FIXED(x) ((fx32)(x) << FIXED_POINT_BITS) #define FROM_FIXED(x) ((x) >> FIXED_POINT_BITS) +#define FP_TO_FIXED(x) (fx32)((x) * FIXED_POINT_BITS) typedef struct{ fx32 x, y; |
