Last change
on this file was
167,
checked in by mulligan, 10 years ago

Fast inverse square root C code, emulator mostly does fine running it
(a small bug found, to be fixed next week).

File size:
317 bytes

Line  

1  #include "stdio.h" 

2  

3  float inv_sqrt(float x) 

4  { 

5  union { 

6  float f; 

7  int i; 

8  } tmp; 

9  tmp.f = x; 

10  tmp.i = 0x5f3759df  (tmp.i >> 1); 

11  float y = tmp.f; 

12  return y * (1.5f  0.5f * x * y * y); 

13  } 

14  

15  int main() 

16  { 

17  float f; 

18  int i; 

19  f = inv_sqrt(16); 

20  i = (int)(1.0f / f); 

21  if(i == 4) 

22  return 5; 

23  else 

24  return 7; 

25  } 

Note: See
TracBrowser
for help on using the repository browser.