Advertisement
Guest User

Untitled

a guest
Aug 3rd, 2015
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. unsigned int fibonacci_closed(unsigned int n) {
  2. double term_number = (double) n;
  3. double golden_ratio = (1 + sqrt(5)) / 2;
  4. double numerator = pow(golden_ratio, term_number);
  5. return round(numerator/sqrt(5));
  6. }
  7.  
  8. 1>ClCompile:
  9. 1> fibonacci_closed.c
  10. 1>c:usersodpdocumentsvisual studio 2010projectsfibonaccifibonaccifibonacci_closed.c(7): warning C4013: 'round' undefined; assuming extern returning int
  11. 1>fibonacci_closed.obj : error LNK2019: unresolved external symbol _round referenced in function _fibonacci_closed
  12.  
  13. static inline double round(double val)
  14. {
  15. return floor(val + 0.5);
  16. }
  17.  
  18. double round_replace(double val) {
  19. if (val > 0.0) return floor(val + 0.5);
  20. if (val < 0.0) return ceil(val - 0.5);
  21. return val;
  22. }
  23.  
  24. round_replace(inf) --> inf
  25. round_replace(1.5) --> 2
  26. round_replace(1.1) --> 1
  27. round_replace(0.9) --> 1
  28. round_replace(0.5) --> 1
  29. round_replace(0.4) --> 0
  30. round_replace(0.1) --> 0
  31. round_replace(0) --> 0
  32. round_replace(-0) --> -0
  33. round_replace(-0.1) --> -0
  34. round_replace(-0.4) --> -0
  35. round_replace(-0.5) --> -1
  36. round_replace(-0.9) --> -1
  37. round_replace(-1.1) --> -1
  38. round_replace(-1.5) --> -2
  39. round_replace(-inf) --> -inf
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement