expected an expression error

1
2
3
if ((floorf(((X[k][i]-X[k-1][i])/X[k][i])*1000)/1000)) == 0.055)    //chk %error = 0.055 and stop
			print(k);
			break;

i am writing these codes in visual studio and i m getting a red zigzag underline below the '==' sign saying 'expected an expression'.
can i not compare these values.X[][] is float.
(i have included math.h)
Look at your parenthesis.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
if
(
    ( 
        floorf
        (
            (
                (
                    X[k][i]-X[k-1][i]
                ) 
                / X[k][i] 
            )
            *1000
        ) 
        /1000
    )
) //This should be removed.
== 0.055
)


You have an extra parenthesis before the == sign.

[code]
On comparing floating point values: http://www.parashift.com/c++-faq/floating-point-arith.html

While you are at it, also make it readable (don't you have to read your own code, over and over again?). Something like this, perhaps:

1
2
3
4
5
6
7
8
9
10
11
double scaled_delta = double( X[k][i] - X[k-1][i] ) / X[k][i] ;
// check nan, inf ? 
if( scaled_delta < 0.1 )
{
    long long value = std::floor( scaled_delta * 1000 ) ;
    if( v == 55 )
    {
        print(k);
        break ;
    }
}



thanx giblit, i totally was unaware...
thanx jlborges, i ll do that for sure...
Topic archived. No new replies allowed.