Module java.base
Package java.lang

Class StrictMath

java.lang.Object
java.lang.StrictMath

public final classStrictMathextendsObject
The classStrictMath contains methods for performing basic numeric operations such as the elementary exponential, logarithm, square root, and trigonometric functions.

To help ensure portability of Java programs, the definitions of some of the numeric functions in this package require that they produce the same results as certain published algorithms. These algorithms are available from the well-known network librarynetlib as the package "Freely Distributable Math Library,"fdlibm. These algorithms, which are written in the C programming language, are then to be understood to be transliterated into Java and executed with all floating-point and integer operations following the rules of Java arithmetic. The following transformations are used in the transliteration:

  • Extraction and setting of the high and low halves of a 64-bitdouble in C is expressed using Java platform methods that perform bit-wise conversionsfromdouble to long andlong todouble.
  • Unsignedint values in C are mapped to signed int values in Java with updates to operations to replicate unsigned semantics where the results on the same textual operation would differ. For example,>> shifts on unsigned C values are replaced with>>> shifts on signed Java values. Sized comparisons on unsigned C values (<,<=,>,>=) are replaced with semantically equivalent calls tocompareUnsigned.

The Java math library is defined with respect tofdlibm version 5.3. Wherefdlibm provides more than one definition for a function (such asacos), use the "IEEE 754 core function" version (residing in a file whose name begins with the lettere). The methods which requirefdlibm semantics aresin,cos,tan,asin,acos,atan,exp,log,log10,cbrt,atan2,pow,sinh,cosh,tanh,hypot,expm1, andlog1p.

The platform uses signed two's complement integer arithmetic with int and long primitive types. The developer should choose the primitive type to ensure that arithmetic operations consistently produce correct results, which in some cases means the operations will not overflow the range of values of the computation. The best practice is to choose the primitive type and algorithm to avoid overflow. In cases where the size isint orlong and overflow errors need to be detected, the methods whose names end withExact throw anArithmeticException when the results overflow.

IEEE 754 Recommended Operations

TheMath class discusses how the shared quality of implementation criteria for selectedMath andStrictMath methodsrelate to the IEEE 754 recommended operations.
Since:
1.3
See Also: