Last change
on this file since 3174 was
180,
checked in by mulligan, 10 years ago

Arctan floating point approximation code. 8051 really struggles with
this.

File size:
522 bytes

Line  

1  float fpow(float b, int r) 

2  { 

3  if(r == 0) 

4  return 1.0f; 

5  else 

6  return b * fpow(b, r  1); 

7  } 

8  

9  float arctan(float x, int precision) 

10  { 

11  int i; 

12  int m; 

13  float r; 

14  r = 0.0f; 

15  m = 1; 

16  for(i = 1; i <= precision; i += 2) 

17  { 

18  r += m * (fpow(x, i) / i); 

19  m *= 1; 

20  } 

21  return r; 

22  } 

23  

24  int main() 

25  { 

26  float f; 

27  // DPM: According to Google this is 0.785398163, but with this precision more 

28  // like 0.723 (according to GCC). 

29  f = arctan(1.0f, 7); 

30  if(f >= 0.7 && f <= 0.8) 

31  return 5; 

32  else 

33  return 7; 

34  } 

35  

36  

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