Thread: if( 3.14 == inf ){} produces compiler error

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    204

    if( 3.14 == inf ){} produces compiler error

    The code
    Code:
    cout <<  " max = " << max << endl;
    outputs
    Code:
     max = inf
    The code
    Code:
    if( 3.14 == inf )
    or specifically the code
    Code:
    if( max == inf )
    won't compile. How can I determine if max is equal to infinity?

  2. #2
    Registered User IdioticCreation's Avatar
    Join Date
    Nov 2006
    Location
    Lurking about
    Posts
    229
    What is inf originally defined as? and are you using float?

  3. #3
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    What's the exact error?
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  4. #4
    carry on JaWiB's Avatar
    Join Date
    Feb 2003
    Location
    Seattle, WA
    Posts
    1,972
    the numeric_limits<> class has a has_infinity member and an infinity() function
    "Think not but that I know these things; or think
    I know them not: not therefore am I short
    Of knowing what I ought."
    -John Milton, Paradise Regained (1671)

    "Work hard and it might happen."
    -XSquared

  5. #5
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    Quote Originally Posted by manutd
    What's the exact error?
    Code:
    Rfilt.cpp: In member function `void Cwn::bounds()':
    Rfilt.cpp:299: error: `inf' undeclared (first use this function)
    Rfilt.cpp:299: error: (Each undeclared identifier is reported only once for
       each function it appears in.)

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    Quote Originally Posted by IdioticCreation
    What is inf originally defined as? and are you using float?
    "inf" is the value of "max." Max is a double.

  7. #7
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    SHow us your complete code.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  8. #8
    Registered User
    Join Date
    Aug 2005
    Posts
    204
    Quote Originally Posted by manutd
    SHow us your complete code.
    I'll show you the member function.
    Code:
    void Cwn::bounds()
    {
    	long i;
    	double max = 0.0, min = 0.0;
    
    	
    	for ( i = 0; i < samp2; i++)
    	{	
    		if ( max < array2[i] )
    			max = array2[i];
    		if ( min > array2[i] )
    			min = array2[i];
    	}
    
    	cout << "from bounds(): " <<  " max of array2 = " << max << endl;
    	cout << "from bounds(): " <<  " min of array2 = " << min << endl;
    
    	if(  max == inf ) 
    	{
    		cout << "Error: Filter unstable. Try setting -qual to a higher value." << endl;
    		exit(0);
    	}
    	
    	
    }

  9. #9
    MFC killed my cat! manutd's Avatar
    Join Date
    Sep 2006
    Location
    Boston, Massachusetts
    Posts
    870
    More. Attach a text file if needed.
    Silence is better than unmeaning words.
    - Pythagoras
    My blog

  10. #10
    Registered User Tonto's Avatar
    Join Date
    Jun 2005
    Location
    New York
    Posts
    1,465
    >> the numeric_limits<> class has a has_infinity member and an infinity() function

    http://www.tacc.utexas.edu/resources...r/num_5679.htm

    Code:
    Example
    
    //
    // limits.cpp
    //
     #include <limits>
    
    
     int main() 
     {
        numeric_limits<float> float_info;
        if (float_info.is_specialized && float_info.has_infinity)
        {
          // get value of infinity 
          float finfinity=float_info.infinity(); 
        }
        return 0;
     }

  11. #11
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    You still didn't say what inf actually is. You say it is the value of max, but how is it declared/defined. There is no "inf" in C++, so if you are using it you have to define it yourself. Show the code where you do that.

  12. #12
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Isn't it obvious? He doesn't declare it.

    Use Tonto's suggestion to fix the problem.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  13. #13
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Isn't it obvious? He doesn't declare it.
    Obviously it is not declared in the posted code, but thetinman indicated that it was assigned to max, which you can assume he or she might think is being done elsewhere. There is a misunderstanding there that needs to be fixed before JaWiB's and Tonto's suggestions can be used.

  14. #14
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    He said "inf" was output to the console, so he wrote it into his code. "inf" is not globally defined, it is not a variable. You have to define it as being the maximum value yourself.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  2. Quantum Random Bit Generator
    By shawnt in forum C++ Programming
    Replies: 62
    Last Post: 06-18-2008, 10:17 AM
  3. Avoiding Global variables
    By csonx_p in forum Windows Programming
    Replies: 32
    Last Post: 05-19-2008, 12:17 AM
  4. failure to import external C libraries in C++ project
    By nocturna_gr in forum C++ Programming
    Replies: 3
    Last Post: 12-02-2007, 03:49 PM
  5. Looking for feedback on program segment
    By avron in forum C++ Programming
    Replies: 4
    Last Post: 05-07-2007, 04:38 PM