Compares the two specified float values. There are two special cases: Float.NaN is equal to Float.NaN and it is greater than any other float value, including Float.POSITIVE_INFINITY; +0.0f is greater than -0.0f @param float1 the first
(float float1, float float2)
| 345 | * @since 1.4 |
| 346 | */ |
| 347 | public static int compare(float float1, float float2) { |
| 348 | // Non-zero, non-NaN checking. |
| 349 | if (float1 > float2) { |
| 350 | return 1; |
| 351 | } |
| 352 | if (float2 > float1) { |
| 353 | return -1; |
| 354 | } |
| 355 | if (float1 == float2 && 0.0f != float1) { |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | // NaNs are equal to other NaNs and larger than any other float |
| 360 | if (isNaN(float1)) { |
| 361 | if (isNaN(float2)) { |
| 362 | return 0; |
| 363 | } |
| 364 | return 1; |
| 365 | } else if (isNaN(float2)) { |
| 366 | return -1; |
| 367 | } |
| 368 | |
| 369 | // Deal with +0.0 and -0.0 |
| 370 | int f1 = floatToRawIntBits(float1); |
| 371 | int f2 = floatToRawIntBits(float2); |
| 372 | // The below expression is equivalent to: |
| 373 | // (f1 == f2) ? 0 : (f1 < f2) ? -1 : 1 |
| 374 | // because f1 and f2 are either 0 or Integer.MIN_VALUE |
| 375 | return (f1 >> 31) - (f2 >> 31); |
| 376 | } |
| 377 | |
| 378 | /** |
| 379 | * Returns a {@code Float} instance for the specified float value. |
no test coverage detected