-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_rsqrt.c
30 lines (27 loc) · 1.17 KB
/
ft_rsqrt.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_rsqrt.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: edelangh <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/01/22 14:07:42 by edelangh #+# #+# */
/* Updated: 2015/01/22 14:23:19 by edelangh ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
float ft_rsqrt(float number)
{
long i;
float x2;
float 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));
y = y * (threehalfs - (x2 * y * y));
return (y);
}