From 5774ceb9e10f56f18194e06bcbe4376563629464 Mon Sep 17 00:00:00 2001 From: Alex Date: Thu, 29 Dec 2022 07:46:55 +0200 Subject: [PATCH] Float stuff --- Library/Convert.c | 28 ++++++++++++++++++++++++++++ include/convert.h | 5 +++++ 2 files changed, 33 insertions(+) diff --git a/Library/Convert.c b/Library/Convert.c index eb53c5f..a4dd33e 100644 --- a/Library/Convert.c +++ b/Library/Convert.c @@ -660,6 +660,34 @@ float sqrtf(float x) return guess; } +double clamp(double x, double low, double high) +{ + if (x < low) + return low; + else if (x > high) + return high; + else + return x; +} + +float lerp(float a, float b, float t) +{ + return (1 - t) * a + t * b; +} + +float smoothstep(float a, float b, float t) +{ + t = clamp(t, 0.0, 1.0); + return lerp(a, b, t * t * (3 - 2 * t)); +} + +float cubicInterpolate(float a, float b, float t) +{ + float t2 = t * t; + float t3 = t2 * t; + return a + (-2 * t3 + 3 * t2) * b; +} + char *strtok(char *src, const char *delim) { static char *src1; diff --git a/include/convert.h b/include/convert.h index 21ae612..2684b73 100644 --- a/include/convert.h +++ b/include/convert.h @@ -18,6 +18,11 @@ extern "C" char *reverse(char *Buffer, int i, int j); float sqrtf(float x); + double clamp(double x, double low, double high); + + float lerp(float a, float b, float t); + float smoothstep(float a, float b, float t); + float cubicInterpolate(float a, float b, float t); void backspace(char s[]); void append(char s[], char n);