Here you can find the source of floatToSortableInt(float val)
float
value to a sortable signed int
.
public static int floatToSortableInt(float val)
//package com.java2s; // Licensed under the Apache License, Version 2.0 (the "License"); public class Main { /**//from w w w . j av a 2 s .co m * Converts a <code>float</code> value to a sortable signed <code>int</code>. * The value is converted by getting their IEEE 754 floating-point "float format" * bit layout and then some bits are swapped, to be able to compare the result as int. * By this the precision is not reduced, but the value can easily used as an int. * The sort order (including {@link Float#NaN}) is defined by * {@link Float#compareTo}; {@code NaN} is greater than positive infinity. * @see #sortableIntToFloat */ public static int floatToSortableInt(float val) { return sortableFloatBits(Float.floatToIntBits(val)); } /** Converts IEEE 754 representation of a float to sortable order (or back to the original) */ public static int sortableFloatBits(int bits) { return bits ^ (bits >> 31) & 0x7fffffff; } }