Guest User

Untitled

a guest
May 21st, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.43 KB | None | 0 0
  1. double rsqrt(double x) {
  2.     double left, right;
  3.     if (x < 1.0) {
  4.         if (x < 0.0) {
  5.             long long nan = 0x7ff8000000000000L;
  6.             return *(double*)&nan;
  7.         }
  8.         left = x;
  9.         right = 1.0;
  10.     } else {
  11.         left = 1.0;
  12.         right = x;
  13.     }
  14.     double root = 1.0, oldRoot = 1.0;
  15.     for (;;) {
  16.         double root = (right + left) / 2.0;
  17.         if (root == oldRoot) return root;
  18.         if (root * root > x) right = root;
  19.         else left = root;
  20.         oldRoot = root;
  21.     }
  22. }
Add Comment
Please, Sign In to add comment