Binary Search on real and float numbers

Правка en2, от BanazadehAria, 2019-06-05 08:59:09

Hi guys, This is the code for binary search on real and float numbers

#include<bits/stdc++.h>
using namespace std;

//We want to find an element which a<0.0000001

const float target = 0.0000001;

int main()
{
    float l=0.00000000,r=100000.00000000;
    cout << l << " " << r;
    while((r-l)>0.0000000001){
        float mid = (float)((l+r)/2);
        cout << mid << endl;
        if(mid>target) r=mid;
        else l=mid;
    }cout << l;
}

But it will stop when it reaches 10 to power -5 what can I do to make it go until 10 to power -18?

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский BanazadehAria 2019-06-05 08:59:09 5 Tiny change: '-l)>0.00001){\n ' -> '-l)>0.0000000001){\n '
en1 Английский BanazadehAria 2019-06-05 08:58:25 615 Initial revision (published)