United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-4345903 On x86 platforms, C1 Math.{sin, cos} implementations violate the 1.3 spec
JDK-4345903 : On x86 platforms, C1 Math.{sin, cos} implementations violate the 1.3 spec

Details
Type:
Bug
Submit Date:
2000-06-15
Status:
Resolved
Updated Date:
2001-05-24
Project Name:
JDK
Resolved Date:
2001-05-24
Component:
hotspot
OS:
solaris_2.6,windows_nt,solaris_7,windows_95
Sub-Component:
compiler
CPU:
x86,sparc
Priority:
P4
Resolution:
Fixed
Affected Versions:
1.3.0
Fixed Versions:
1.4.0 (beta2)

Related Reports
Duplicate:
Relates:
Relates:
Relates:
Relates:
Relates:
Relates:

Sub Tasks

Description
In 1.3, the specification for java.lang.Math.{sin, cos} was changed
from an operational definition (use FDLIBM algorithms) to a
declarative one (use any approximation with 1 ulp accuracy and good
monotonicity properties).  On x86 platforms, for values smaller in
magnitude than 2^63, effectively the C1 and C2 compilers use the raw
x86 instructions fsin and fcos to implement Math.{sin, cos}.  This
does not follow the spec since the 66 bit argument reduction used by
fsin/fcos introduces large deviations from the true values of sine and
cosine for some inputs.  Outside of +/-2^63, C1 and C2 use FDLIBM
algorithms which do proper argument reduction.  This introduces an
inconsistency in the periodicity of the approximation to sine/cosine.

The solution is to have the Math.{sin, cos} do their own argument
reduction to [-pi/4, pi/4] and then call fsin/fcos; this will
guarantee the specified accuracy and monotonicity properties.  The
needed argument reduction functions are already available from FDLIBM,
http://www.netlib.org/fdlibm.

                                    

Comments
PUBLIC COMMENTS

On x86 platforms, C1 and C2 use the fsin and fcos instructions to
implement java.lang.Math.{sin, cos} without fully compensating for the
accuracy and range limitations of those instructions -- leading to
java.lang.Math.{sin, cos} implementations that don't meet the accuracy
requirements of the 1.3 specification.
                                     
2004-06-10
SUGGESTED FIX

Instead of relying on fsin/fcos over the supported range and falling
back to FDLIBM outside that range, have Java's {sin,cos} do their own
argument reduction to [-pi/4, pi/4] and then call fsin/fcos (this is
one practice recommended by Intel).  The FDLIBM routine e_rem_pio2
does sufficiently accurate argument reduction; it returns an array of
two 64-bit double values representing the reduced argument.  One small
wrinkle is that these two values must be added in double extended
precision (80 bit format) before fsin/fcos is called; that ensures the
error in the argument reduction doesn't adversely affect the final
result.  Otherwise, the logic of the new sin routine is the same as
the FDLIBM s_sin.c routine except fsin/fcos are used instead of
FDLIBM's __kernel_sin and __kernel_cos.  FDLIBM is publicly available
from Netlib, http://www.netlib.org/fdlibm, and was written by
numerical analysts now working at Sun.
                                     
2004-06-11
WORK AROUND

Use the methods in the FDLIBM-based java.lang.StrictMath to implement java.lang.Math.
                                     
2004-06-11
EVALUATION

Fixed for merlin beta refresh. Interpreter code has been changed to an inlined
routine and revised to be more efficient based on suggestions from Joe.Darcy@eng
and Cliff.Click@eng; C1 now uses this code as well.

kenneth.russell@eng 2001-04-27
                                     
2004-06-11
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
merlin-beta2

FIXED IN:
merlin-beta2

INTEGRATED IN:
merlin-beta2


                                     
2004-06-14



Hardware and Software, Engineered to Work Together