mardi 1 mai 2018

0.1 vs 0,1 in c++, why does neither result an error? [duplicate]

This question already has an answer here:

I come from a country where the way we write decimal numbers differs from the other place by whether I use ',' or '.' for decimal separator. Now this is why I by accident wrote somewhere in my c++ program:

while(true){
    long double x=0;
    //some code that increases the value of x 
    //by very small amount but it doesn't leave it at 0
    if(x>0,000001)break;
}

And this made the program run indefinitely. After wasting quite some time thinking my code was wrong I tried this:

while(true){
    long double x=0;
    //some code that increases the value of x 
    //by very small amount but it doesn't leave it at 0
    if(x>0.000001)break;
}

Which worked just fine. Later I understood my mistake (I used ',' instead of '.'), but now I am confused as to why doesn't the next code result with compilation error, and how come it's outcome is "greater"

long double g=0.001;
if(g>0,01)cout<<"greater";
else cout<<"smaller";

Aucun commentaire:

Enregistrer un commentaire