Float stuff

This commit is contained in:
Alex 2022-12-29 07:46:55 +02:00
parent ce8caa9f89
commit 5774ceb9e1
Signed by untrusted user who does not match committer: enderice2
GPG Key ID: EACC3AD603BAB4DD
2 changed files with 33 additions and 0 deletions

View File

@ -660,6 +660,34 @@ float sqrtf(float x)
return guess; 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) char *strtok(char *src, const char *delim)
{ {
static char *src1; static char *src1;

View File

@ -18,6 +18,11 @@ extern "C"
char *reverse(char *Buffer, int i, int j); char *reverse(char *Buffer, int i, int j);
float sqrtf(float x); 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 backspace(char s[]);
void append(char s[], char n); void append(char s[], char n);