-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
1.2.2
-
x86
-
windows_nt
Name: skT88420 Date: 07/19/99
Application stores Long.MAX_VALUE in a long and in a double,
then casts the long to a double and compares to the first double.
The two doubles do not compare as equal because the result of
the cast is off by one. This does not happen with the first
comparison - in the following test program, it starts to fail
on the 33rd iteration. Presumably, JIT kicks in at that
iteration. The bug does not happen with HotSpot, nor does
it happen with JDK 1.1.7B or JDK 1.1.8.
The test program follows:
---
public class test
{
static public void main(String args[])
{
for (int i = 1; i < 101; i++)
{
SQLLongint li = new SQLLongint(Long.MAX_VALUE);
SQLDouble d = new SQLDouble(Long.MAX_VALUE);
if ( ! d.equals(d, li))
{
System.out.println("FALSE! - iteration " + i + ", difference is " + (d.getDouble() - li.getDouble()));
}
}
}
}
class SQLLongint
{
long value;
SQLLongint(long val)
{
value = val;
}
double getDouble()
{
return (double) value;
}
}
class SQLDouble
{
double value;
SQLDouble(double val)
{
value = val;
}
double getDouble()
{
return value;
}
boolean equals(SQLDouble left, SQLLongint right)
{
return left.getDouble() == right.getDouble();
}
}
---
(Review ID: 85772)
======================================================================