Ian Rogers writes:
> Andrew Haley wrote:
> > We know that any calculation involving NaN returns false, right? So,
> > simple cases can be done first without the (possibly expensive) move
> > out of the FPU:
> >
> > if (x < y)
> > return -1;
> > if (x > y)
> >
Andrew Haley wrote:
We know that any calculation involving NaN returns false, right? So,
simple cases can be done first without the (possibly expensive) move
out of the FPU:
if (x < y)
return -1;
if (x > y)
return 1;
then you can do the doubleToLongBits:
Ian Rogers writes:
> Ian Rogers wrote:
> > public static int compare(float x, float y)
> > {
> > if (isNaN(x))
> > return isNaN(y) ? 0 : 1;
> >if (isNaN(y))
> > return -1;
> > // recall that 0.0 == -0.0, so we convert to infinities and try again
> > if (x == 0
On Sat, 2007-06-30 at 16:57 -0400, Ian Rogers wrote:
> In terms of performance I just tried sorting an array of floats with the
> new code (floatAsIntBits should have been floatToIntBits, sorry). The
> test was to initialize an array of floats backwards and then sort it to
> be ascending. Runnin
Hi Mark,
Mark Wielaard wrote:
Hi Ian,
On Sat, 2007-06-30 at 15:25 -0400, Ian Rogers wrote:
public static int compare(float x, float y)
{
int ix = floatAsIntBits(x);
int iy = floatAsIntBits(y);
if (ix == iy) return 0;
if (isNaN(x)) return 1;
if (isNaN(y)) return -1;
int ix_
Hi Ian,
On Sat, 2007-06-30 at 15:25 -0400, Ian Rogers wrote:
> public static int compare(float x, float y)
> {
>int ix = floatAsIntBits(x);
>int iy = floatAsIntBits(y);
>if (ix == iy) return 0;
>if (isNaN(x)) return 1;
>if (isNaN(y)) return -1;
>int ix_sign = ix>>31;
>i
In terms of performance I just tried sorting an array of floats with the
new code (floatAsIntBits should have been floatToIntBits, sorry). The
test was to initialize an array of floats backwards and then sort it to
be ascending. Running a large enough array and enough iterations to get
a ~4 sec
Ian Rogers wrote:
public static int compare(float x, float y)
{
if (isNaN(x))
return isNaN(y) ? 0 : 1;
if (isNaN(y))
return -1;
// recall that 0.0 == -0.0, so we convert to infinities and try again
if (x == 0 && y == 0)
return (int) (1 / x - 1 / y);
if (x ==
Hi everyone,
I was tracking a bug and came across the code in Float.compare which is
very similar to Double.compare. It just so happened that the bug was
being caused by sorting arrays containing lots of floating point 0s.
This occurs quite frequently in the Jikes RVM when we have an array of
9 matches
Mail list logo