Advertisement
Guest User

Untitled

a guest
Sep 19th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.66 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <stdio.h>
  3.  
  4. double fisr(double number);
  5.  
  6. int main(void) {
  7. double a = 2;
  8. //scanf("%lf", &a);
  9. printf("%lfn", fisr(a));
  10.  
  11. system("pause");
  12. return 0;
  13. }
  14.  
  15. double fisr(double number) {
  16. long i;
  17. float x2, y;
  18. const float threehalfs = 1.5F;
  19.  
  20. x2 = number * 0.5F;
  21. y = number;
  22. i = * ( long * ) &y; // evil floating point bit level hacking
  23. i = 0x5f3759df - ( i >> 1 ); // what the fuck?
  24. y = * ( float * ) &i;
  25. y = y * ( threehalfs + ( x2 * y * y ) ); // 1st iteration
  26. // y = y * ( threehalfs - ( x2 * y * y ) ); // 2nd iteration, this can be removed
  27.  
  28. return y;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement