JDK-4345903 : On x86 platforms, C1 Math.{sin, cos} implementations violate the 1.3 spec
  • Type: Bug
  • Component: hotspot
  • Sub-Component: compiler
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS:
    solaris_2.6,solaris_7,windows_95,windows_nt solaris_2.6,solaris_7,windows_95,windows_nt
  • CPU: x86,sparc
  • Submitted: 2000-06-15
  • Updated: 2015-11-13
  • Resolved: 2001-05-24
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.4.0 beta2Fixed
Related Reports
Duplicate :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
Relates :  
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
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: merlin-beta2 FIXED IN: merlin-beta2 INTEGRATED IN: merlin-beta2
14-06-2004

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
11-06-2004

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

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.
11-06-2004

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.
10-06-2004