#ifndef TWN_UTIL_C_H #define TWN_UTIL_C_H #include "twn_types.h" /* note: you must free the returned string */ char *expand_asterisk(const char *mask, const char *to); /* http://www.azillionmonkeys.com/qed/sqroot.html */ static inline float fast_sqrt(float x) { union { float f; uint32_t u; } pun = {.f = x}; pun.u += 127 << 23; pun.u >>= 1; return pun.f; } static inline Vec2 fast_cossine(float a) { const float s = sinf(a); return (Vec2){ .x = fast_sqrt(1.0f - s * s) * (a >= (float)M_PI_2 && a < (float)(M_PI + M_PI_2) ? -1 : 1), .y = s }; } static inline bool is_power_of_two(int x) { return (x != 0) && ((x & (x - 1)) == 0); } #endif