Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- double rsqrt(double x) {
- double left, right;
- if (x < 1.0) {
- if (x < 0.0) {
- long long nan = 0x7ff8000000000000L;
- return *(double*)&nan;
- }
- left = x;
- right = 1.0;
- } else {
- left = 1.0;
- right = x;
- }
- double root = 1.0, oldRoot = 1.0;
- for (;;) {
- double root = (right + left) / 2.0;
- if (root == oldRoot) return root;
- if (root * root > x) right = root;
- else left = root;
- oldRoot = root;
- }
- }
Add Comment
Please, Sign In to add comment