Skip to content

Commit

Permalink
A few new macros
Browse files Browse the repository at this point in the history
  • Loading branch information
EimaMei committed May 15, 2024
1 parent 4cdc9dd commit 58951e7
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
14 changes: 7 additions & 7 deletions examples/bit.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#define SI_IMPLEMENTATION
#include <sili.h>

inline cstring operatingSystem(void) {
cstring operatingSystem(void) {
static char res[] =
#if defined(SI_SYSTEM_WINDOWS)
"Windows"
Expand All @@ -22,7 +22,7 @@ inline cstring operatingSystem(void) {
}


inline cstring cpuArch(void) {
cstring cpuArch(void) {
static char res[] =
#if defined(SI_CPU_X86)
"x86"
Expand All @@ -48,19 +48,19 @@ inline cstring cpuArch(void) {
return res;
}

inline usize cpu_arch_bit(void) {
usize cpu_arch_bit(void) {
#if defined(SI_ARCH_64_BIT)
return 64;
#elif defined(SI_ARCH_32_BIT)
return 32;
#endif
}

inline cstring cpuEndian(void) {
cstring cpuEndian(void) {
return (SI_HOST_IS_LITTLE_ENDIAN == true) ? "little-endian" : "big-endian";
}

inline cstring compiler(void) {
cstring compiler(void) {
static char res[] =
#if defined(SI_COMPILER_GCC)
"GCC"
Expand All @@ -76,7 +76,7 @@ inline cstring compiler(void) {
return res;
}

inline cstring language(void) {
cstring language(void) {
static char res[] =
#if defined(SI_LANGUAGE_C)
"C"
Expand All @@ -93,7 +93,7 @@ inline cstring language(void) {
return res;
}

inline cstring standard(void) {
cstring standard(void) {
static char res[] =
#if !defined(SI_LANGUAGE_CPP)
#if SI_STANDARD_VERSION == SI_STANDARD_C89
Expand Down
18 changes: 18 additions & 0 deletions sili.h
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,9 @@ typedef struct { u8 r, g, b, a; } siColor;
/* r, g, b - u8
* Macro to define an RGB color. */
#define SI_RGB(r, g, b) SI_RGBA(r, g, b, 255)
/* hex - u32
* Converts an u32 hex value to RGB. */
#define SI_HEX(hex) SI_RGBA(((hex) >> 16) & 0xFF, ((hex) >> 8) & 0xFF, hex & 0xFF, 255)

/* Width and height i32 structure. */
typedef struct { i32 width, height; } siArea;
Expand Down Expand Up @@ -1097,6 +1100,9 @@ typedef struct { f32 x, y; } siVec2;
/* area - siArea
* Macro to define a 2D vector from an area. */
#define SI_VEC2_A(area) SI_VEC2((area).width, (area).height)
/* vec1Ptr - siVec2* | vec2 - siVec2
* Adds vec2 into vec1 */
#define si_vec2Add(vec1Ptr, vec2) (vec1Ptr)->x += vec2.x; (vec1Ptr)->y += vec2.y

/* 3D vector structure. */
typedef struct { f32 x, y, z; } siVec3;
Expand Down Expand Up @@ -2742,6 +2748,14 @@ f64 si_max3F64(f64 a, f64 b, f64 c);
f32 si_max3F32(f32 a, f32 b, f32 c);
#define si_max3f(a, b, c) (sizeof(a) == 4 ? si_max3F32(a, b, c) : si_max3F64(a, b, c))

/* Returns 'lower' if x is lower than it, 'upper' if x is upper than it or itself
* if neither. */
i64 si_clamp(i64 x, i64 lower, i64 upper);
f64 si_clampF64(f64 x, f64 lower, f64 upper);
f32 si_clampF32(f32 x, f32 lower, f32 upper);
#define si_clampf(x, lower, upper) (sizeof(x) == 4 ? si_clampF32(x, lower, upper) : si_clampF64(x, lower, upper))


/* Returns the absolute value of 'x'. */
i64 si_abs(i64 x);
f64 si_absF64(f64 x);
Expand Down Expand Up @@ -6817,6 +6831,10 @@ inline i64 si_max3(i64 a, i64 b, i64 c) { return si_max(si_max(a, b), c); }
inline f64 si_max3F64(f64 a, f64 b, f64 c) { return si_maxF64(si_maxF64(a, b), c); }
inline f32 si_max3F32(f32 a, f32 b, f32 c) { return si_maxF32(si_maxF32(a, b), c); }

inline i64 si_clamp(i64 x, i64 lower, i64 upper) { return si_min(upper, si_max(x, lower)); }
inline f64 si_clampF64(f64 x, f64 lower, f64 upper) {return si_minF64(upper, si_maxF64(x, lower)); }
inline f32 si_clampF32(f32 x, f32 lower, f32 upper) { return si_minF32(upper, si_maxF32(x, lower)); }

inline i64 si_abs(i64 x) { return x < 0 ? -x : x; }
inline f64 si_absF64(f64 x) { return x < 0 ? -x : x; }
inline f32 si_absF32(f32 x) { return x < 0 ? -x : x; }
Expand Down

0 comments on commit 58951e7

Please sign in to comment.