Obviously java.lang.StrictMath contains additional functions (hyperbolics etc.) which java.lang.Math doesn\'t, but is there a difference in the functions which are found in
The Javadoc for the Math class provides some information on the differences between the two classes:
Unlike some of the numeric methods of class
StrictMath
, all implementations of the equivalent functions of classMath
are not defined to return the bit-for-bit same results. This relaxation permits better-performing implementations where strict reproducibility is not required.By default many of the
Math
methods simply call the equivalent method inStrictMath
for their implementation. Code generators are encouraged to use platform-specific native libraries or microprocessor instructions, where available, to provide higher-performance implementations ofMath
methods. Such higher-performance implementations still must conform to the specification forMath
.
Therefore, the Math
class lays out some rules about what certain operations should do, but they do not demand that the exact same results be returned in all implementations of the libraries.
This allows for specific implementations of the libraries to return similiar, but not the exact same result if, for example, the Math.cos
class is called. This would allow for platform-specific implementations (such as using x86 floating point and, say, SPARC floating point) which may return different results.
(Refer to the Software Implementations section of the Sine article in Wikipedia for some examples of platform-specific implementations.)
However, with StrictMath, the results returned by different implementations must return the same result. This would be desirable for instances where the reproducibility of results on different platforms are required.