aboutsummaryrefslogtreecommitdiff
path: root/src/un_math.c
diff options
context:
space:
mode:
authorbonmas14 <bonmas14@gmail.com>2025-08-04 13:33:47 +0000
committerbonmas14 <bonmas14@gmail.com>2025-08-04 13:33:47 +0000
commited1cab483e49e29396178a33dea51773aa770855 (patch)
tree78102102f7f7d07be0e6bef4b10ef69576f0c23e /src/un_math.c
parent471b539bdbf658ff7924b7500f89fd237df8be9b (diff)
downloadungrateful-ed1cab483e49e29396178a33dea51773aa770855.tar.gz
ungrateful-ed1cab483e49e29396178a33dea51773aa770855.zip
Math, not tested
Diffstat (limited to 'src/un_math.c')
-rw-r--r--src/un_math.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/src/un_math.c b/src/un_math.c
new file mode 100644
index 0000000..772ef70
--- /dev/null
+++ b/src/un_math.c
@@ -0,0 +1,99 @@
+/* reals */
+
+real un_m_lerpr(real a, real b, real t) {
+ return (1.0 - t) * a + b * t;
+}
+
+real un_m_ease_isiner(real t) {
+#if defined(UN_DOUBLE_PRECISION)
+ return 1.0 - cos((t * PI) / 2.0);
+#else
+ return 1.0 - cosf((t * PI) / 2.0);
+#endif
+}
+
+real un_m_ease_iosiner(real t) {
+#if defined(UN_DOUBLE_PRECISION)
+ return sin((t * PI) / 2.0f);
+#else
+ return sinf((t * PI) / 2.0f);
+#endif
+}
+
+real un_m_ease_osiner(real t) {
+#if defined(UN_DOUBLE_PRECISION)
+ return -(cos(t * PI) - 1.0) / 2.0;
+#else
+ return -(cosf(t * PI) - 1.0) / 2.0;
+#endif
+}
+
+real un_m_ease_iquadr(real t) {
+ return t * t;
+}
+
+real un_m_ease_ioquadr(real t) {
+ return 1.0 - (1.0 - t) * (1.0 - t);
+}
+
+real un_m_ease_oquadr(real t) {
+ return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0;
+}
+
+/* floats */
+f32 un_m_lerpf(f32 a, f32 b, f32 t) {
+ return (1.0 - t) * a + b * t;
+}
+
+f32 un_m_ease_isinef(f32 t) {
+ return 1.0 - cosf((t * PI) / 2.0);
+}
+
+f32 un_m_ease_iosinef(f32 t) {
+ return sinf((t * PI) / 2.0f);
+}
+
+f32 un_m_ease_osinef(f32 t) {
+ return -(cosf(t * PI) - 1.0) / 2.0;
+}
+
+f32 un_m_ease_iquadf(f32 t) {
+ return t * t;
+}
+
+f32 un_m_ease_ioquadf(f32 t) {
+ return 1.0 - (1.0 - t) * (1.0 - t);
+}
+
+f32 un_m_ease_oquadf(f32 t) {
+ return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0;
+}
+
+/* doubles */
+f64 un_m_lerpd(f64 a, f64 b, f64 t) {
+ return (1.0 - t) * a + b * t;
+}
+
+f64 un_m_ease_isined(f64 t) {
+ return 1.0 - cos((t * PI) / 2.0);
+}
+
+f64 un_m_ease_iosined(f64 t) {
+ return sin((t * PI) / 2.0f);
+}
+
+f64 un_m_ease_osined(f64 t) {
+ return -(cos(t * PI) - 1.0) / 2.0;
+}
+
+f64 un_m_ease_iquadd(f64 t) {
+ return t * t;
+}
+
+f64 un_m_ease_ioquadd(f64 t) {
+ return 1.0 - (1.0 - t) * (1.0 - t);
+}
+
+f64 un_m_ease_oquadd(f64 t) {
+ return t < 0.5 ? 2.0 * t * t : 1.0 - ((-2.0 * t + 2.0) * (-2.0 * t + 2.0)) / 2.0;
+}