math header

This commit is contained in:
Derek Hensley
2024-05-21 18:06:36 -07:00
parent 88868ee2f2
commit e2b4b1bbd1
57 changed files with 237 additions and 236 deletions
+5 -4
View File
@@ -1,10 +1,11 @@
#ifndef LIBC_MATH_H
#define LIBC_MATH_H
#define M_PI 3.14159265358979323846f
#define M_SQRT2 1.41421356237309504880f
#define M_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */
#define FLT_MAX 340282346638528859811704183484516925440.0f
#define F_PI 3.14159265358979323846f
#define F_SQRT2 1.41421356237309504880f
#define F_SQRT1_2 0.70710678118654752440f /* 1/sqrt(2) */
#define FLT_MAX 3.40282347e+38f
#define SHT_MAX 32767.0f
#define SHT_MINV (1.0f / SHT_MAX)
+8 -8
View File
@@ -168,21 +168,21 @@ typedef union {
#define TRUNCF_BINANG(f) (s16)(s32)(f)
// Angle conversion macros
#define DEG_TO_RAD(degrees) ((degrees) * (M_PI / 180.0f))
#define DEG_TO_RAD(degrees) ((degrees) * (F_PI / 180.0f))
#define DEG_TO_BINANG(degrees) TRUNCF_BINANG((degrees) * (0x8000 / 180.0f))
#define DEG_TO_BINANG_ALT(degrees) TRUNCF_BINANG(((degrees) / 180.0f) * 0x8000)
#define DEG_TO_BINANG_ALT2(degrees) TRUNCF_BINANG(((degrees) * 0x10000) / 360.0f)
#define DEG_TO_BINANG_ALT3(degrees) ((degrees) * (0x8000 / 180.0f))
#define RAD_TO_DEG(radians) ((radians) * (180.0f / M_PI))
#define RAD_TO_BINANG(radians) TRUNCF_BINANG((radians) * (0x8000 / M_PI))
#define RAD_TO_BINANG_ALT(radians) TRUNCF_BINANG(((radians) / M_PI) * 0x8000)
#define RAD_TO_BINANG_ALT2(radians) TRUNCF_BINANG(((radians) * 0x8000) / M_PI)
#define RAD_TO_DEG(radians) ((radians) * (180.0f / F_PI))
#define RAD_TO_BINANG(radians) TRUNCF_BINANG((radians) * (0x8000 / F_PI))
#define RAD_TO_BINANG_ALT(radians) TRUNCF_BINANG(((radians) / F_PI) * 0x8000)
#define RAD_TO_BINANG_ALT2(radians) TRUNCF_BINANG(((radians) * 0x8000) / F_PI)
#define BINANG_TO_DEG(binang) ((f32)(binang) * (180.0f / 0x8000))
#define BINANG_TO_RAD(binang) ((f32)(binang) * (M_PI / 0x8000))
#define BINANG_TO_RAD_ALT(binang) (((f32)(binang) / 0x8000) * M_PI)
#define BINANG_TO_RAD_ALT2(binang) (((f32)(binang) * M_PI) / 0x8000)
#define BINANG_TO_RAD(binang) ((f32)(binang) * (F_PI / 0x8000))
#define BINANG_TO_RAD_ALT(binang) (((f32)(binang) / 0x8000) * F_PI)
#define BINANG_TO_RAD_ALT2(binang) (((f32)(binang) * F_PI) / 0x8000)
// Angle arithmetic macros
#define BINANG_ROT180(angle) ((s16)(angle + 0x8000))