The code

outputsCode:`cout << " max = " << max << endl;`

The codeCode:`max = inf`

or specifically the codeCode:`if( 3.14 == inf )`

won't compile. How can I determine if max is equal to infinity?Code:`if( max == inf )`

Printable View

- 01-21-2007thetinmanif( 3.14 == inf ){} produces compiler error
The code

Code:`cout << " max = " << max << endl;`

Code:`max = inf`

Code:`if( 3.14 == inf )`

Code:`if( max == inf )`

- 01-21-2007IdioticCreation
What is inf originally defined as? and are you using float?

- 01-21-2007manutd
What's the exact error?

- 01-21-2007JaWiB
the numeric_limits<> class has a has_infinity member and an infinity() function

- 01-21-2007thetinmanQuote:

Originally Posted by**manutd**

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.)

- 01-21-2007thetinmanQuote:

Originally Posted by**IdioticCreation**

- 01-21-2007manutd
SHow us your complete code.

- 01-21-2007thetinmanQuote:

Originally Posted by**manutd**

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);

}

}

- 01-21-2007manutd
More. Attach a text file if needed.

- 01-21-2007Tonto
>> 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;

}

- 01-22-2007Daved
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.

- 01-22-2007Sang-drax
Isn't it obvious? He doesn't declare it.

Use Tonto's suggestion to fix the problem. - 01-22-2007Daved
>> 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. - 01-22-2007Perspective
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.