Is it a Bug in g++ compiler`s -O flag??

Discussion in 'C++' started by nikhil_dokania, Oct 16, 2006.

Thread Status:
Not open for further replies.
  1. nikhil_dokania

    nikhil_dokania New Member

    Joined:
    Oct 16, 2006
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    The output is different for the following two codes when compiled as : "g++ -O foo.cpp"
    1st COde :
    Code:
    #include<iostream.h>
    #include<math.h>
    int main(){
    	double d=log(8)/log(2);
    	cout<<"d="<<d<<"\t floor(d)="<<floor(d);        //<<"\t"<<floor(10.0)<<"\n";
    	return 0;
    }
    ------------------------------------------------------------------------------------------------------------------
    2nd COde :
    Code:
    #include<iostream.h>
    #include<math.h>
    int main(){
    	double d=log(8)/log(2);
    	cout<<"d="<<d<<"\t floor(d)="<<floor(d)<<"\t"<<floor(10.0)<<"\n";
    	return 0;
    }
    ---------------------------------------------------------------------------------------------------------------

    Expected output : d=3 floor(d)=3 10
    But The First code give : d=3 floor(d)=2 10
    while the second gives the right output.
    Could nyone plz explain whats going wrong!!

    Nikhil
     
    Last edited by a moderator: Oct 17, 2006
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83
    Duplicate of [thread=1649]Is it a Bug in g++ compiler`s -O flag?? [/thread]. Thread closed.
     
Thread Status:
Not open for further replies.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice