Question

I am testing float values

    public boolean deviceInGoodPosition() {
    if (filteredSampling.fmagnet_x > 0.0 && filteredSampling.fmagnet_y < 0.0 &&  filteredSampling.fmagnet_y > 0.0 ) { 
        return true;
    } else {
        System.out.println("fmagnet_x " +  filteredSampling.fmagnet_x + " > 0.0  AND  fmagnet_y " + filteredSampling.fmagnet_y  + " < 0.0 AND  fmagnet_z " + filteredSampling.fmagnet_z + " > 0.0");
        return false;
    }
}

but running it, with correct values return false .. I print the values for checking

Starting analyzeThread
analyzeThread requesting calibration
fmagnet_x 19.119263 > 0.0  AND  fmagnet_y -44.880676 < 0.0 AND  fmagnet_z 3.5110474 > 0.0
 Wrong device positioning
Was it helpful?

Solution

Your issue is that filteredSampling.fmagnet_y < 0.0 && filteredSampling.fmagnet_y > 0.0 will never return true, as a number cannot be both positive and negative.

Based on your print statement, I assume you meant the last part to be filteredSampling.fmagnet_z > 0.0 (note the z instead of the y).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top