PS Looks like Hadoop does have a DoubleWritable now -- I'll switch to
that where approrpriate as part of this pretty-big change list I am
preparing.

Also, while scouring the code I spotted what I believe is a common
misconception that has led to a bug or two: {Double,Float}.MIN_VALUE
is *not* the most negative value that a double/float can take on -- it
is the smallest *positive* value it can take on.

If you're looking for a good value to initialize some kind of "max"
variable to, try {Float,Double}.NEGATIVE_INFINITY. It is smaller than
every actual float/double.

If you really need the most negative value, I think you want the
negative of MAX_VALUE, but not 100% sure on that. Actually be careful
there because in some cases I saw code trying to compute:

(Float.MAX_VALUE - Float.MIN_VALUE)

If you fix this to

(Float.MAX_VALUE - (-Float.MAX_VALUE))

well you see the overflow problem.

To generate a truly random float or double, try

Double.longBitsToDouble(Random.nextLong())

though once again I would have to think about whether this actually
generates NaN or INFINITY in some cases!

Reply via email to