Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. double trqs(double a)
  2. {
  3. double low = 0;
  4. double mid = a/2;
  5. double high = a;
  6. double squared = high * high;
  7. const double epsilon = 0.000001;
  8. while(low < high && (squared + epsilon < a * a || squared - epsilon > a * a)){
  9. if( squared + epsilon < a) {
  10. low = (low + mid) / 2;
  11. } else if (squared - epsilon > a) {
  12. high = (high + mid) / 2;
  13. }
  14. mid = (high + low) / 2;
  15. squared = mid * mid;
  16. }
  17.  
  18. return mid;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement