summaryrefslogtreecommitdiff
path: root/src/math/math.c
blob: 4cca29e52f3c6f840c8b80c26e774c02c78209ec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include "math.h"

char printbuffer[2048] = { 0 };

float rsqrt(float number) {
	long i;
	float x2, y;
	const float threehalfs = 1.5F;

	x2 = number * 0.5F;
	y = number;
	i = *(long *)&y;
	i = 0x5f3759df - (i >> 1);
	y = *(float *)&i;
	y = y * (threehalfs - (x2 * y * y));
	return y;
}

float lerp(float a, float b, float t) {
	return a * (1 - t) + b * t;
}