On 6/2/09 1:22 AM, "Chuck Lam" <chuck.lam@gmail.com> wrote:
>
> Counters are integers and most convergence criteria are floating point, so
> you'll have to scale your numbers and round them to integers to approximate
> things. (Like I said, it's a bit of a hack.)
>
No rounding or loss of data is necessary for this sort of operation.
For packing floats into ints, or doubles into longs in Java, there are some
convenient (but not well known) methods to just get the raw bits and assign
as the other type, without a cast conversion.
One can use a Float, and then floatToIntBits, and similar methods, to
extract the raw bits of a float or double and write as an int or long. The
raw bits of an IEEE float lexicographically sort in the same order as the
raw bits of the same sized int too, which is useful.
http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Float.html#floatToIntBits(
float)
|