gXa's blog

By gXa, history, 9 years ago, In English

If N and M are used as double, then for comparing them, can we do this:

if( N<=M ) { cout << "Yes"; }

If not then suggest what to do?

If N is long long and M is double, then for comparing them, can we do this:

if( N<=M ) { cout << "Yes"; }

If not then suggest what to do?

Comparison with double is causing me problem. So guide me what to do?

  • Vote: I like it
  • +5
  • Vote: I do not like it

| Write comment?
»
9 years ago, # |
Rev. 2   Vote: I like it -19 Vote: I do not like it
if(n - m <= EPS){
    cout << "Greater";
}
else{
    cout << "Less";
}
  • »
    »
    9 years ago, # ^ |
      Vote: I like it -13 Vote: I do not like it

    This is for n==m not n<=m. I am assuming EPS as epsilon.

»
9 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it
if (n-m<=eps) { cout<<"yes"; }

where eps=1e-6 or a smallest value;

»
9 years ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

Okay I also want to confirm that value of epsilon should be taken as 10^(-9). I have found most of times that 10^(-6) or numeric::limits epsilon() gives WA.

Guide me on this?