I am writing tests for some methods in the Math class of OpenJDK to get coverage (node coverage, edge coverage, etc).
I created a Control Flow graph and found the test paths to get the different types of coverage. One of the paths involves a conditional that has the following statement:
if(( .... && ... && Float.floatToRawIntBits(b)==negativeZeroFloatBits )) I looked up the documentation as well as another stackoverflow Q but am not fully understanding these two parts of the statement.
floatToRawIntBits is defined as: Returns a representation of the specified floating-point value according to the IEEE 754 floating-point "single format" bit layout, preserving Not-a-Number (NaN) values. Not sure what these even means to be honest? Is it saying the number will STAY a Float, even if its NaN (e.g. 0.0/0.0) ?
What about negativeZeroFloatBits? Is this just equivalent to: Float.floatToRawIntBits(-0.0f)
When would the two be equal? When would they not?
(Documentation: http://ift.tt/1SefYme )
(The Math class can be found here: http://ift.tt/2453d1e)
MIN Method:
public static float min(float a, float b) {
if (a != a)
return a; // a is NaN
if ((a == 0.0f) &&
(b == 0.0f) &&
(Float.floatToRawIntBits(b) == negativeZeroFloatBits)) {
// Raw conversion ok since NaN can't map to -0.0.
return b;
}
return (a <= b) ? a : b;
}
Aucun commentaire:
Enregistrer un commentaire