Math Class
Contains methods for mathematical operations.
The following are fields for Math.
-
Returns the mathematical constant e, which is the base of natural logarithms.
-
Returns the mathematical constant pi, which is the ratio of the circumference of a circle to its diameter.
Returns the mathematical constant e, which is the base of natural logarithms.
public static final Double E
Type: Double
Returns the mathematical constant pi, which is the ratio of the circumference of a circle to its diameter.
public static final Double PI
Type: Double
The following are methods for Math. All methods are static.
-
Returns the absolute value of the specified Decimal.
-
Returns the absolute value of the specified Double.
-
Returns the absolute value of the specified Integer.
-
Returns the absolute value of the specified Long.
-
Returns the arc cosine of an angle, in the range of 0.0 through pi.
-
Returns the arc cosine of an angle, in the range of 0.0 through pi.
-
Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
-
Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
-
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
-
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
-
atan2(xCoordinate, yCoordinate)
Converts rectangular coordinates (xCoordinate and yCoordinate) to polar (r and theta). This method computes the phase theta by computing an arc tangent of xCoordinate/yCoordinate in the range of -pi to pi.
-
atan2(xCoordinate, yCoordinate)
Converts rectangular coordinates (xCoordinate and yCoordinate) to polar (r and theta). This method computes the phase theta by computing an arc tangent of xCoordinate/yCoordinate in the range of -pi to pi.
-
Returns the cube root of the specified Decimal. The cube root of a negative value is the negative of the cube root of that value’s magnitude.
-
Returns the cube root of the specified Double. The cube root of a negative value is the negative of the cube root of that value’s magnitude.
-
Returns the smallest (closest to negative infinity) Decimal that is not less than the argument and is equal to a mathematical integer.
-
Returns the smallest (closest to negative infinity) Double that is not less than the argument and is equal to a mathematical integer.
-
Returns the trigonometric cosine of the angle specified by decimalAngle.
-
Returns the trigonometric cosine of the angle specified by doubleAngle.
-
Returns the hyperbolic cosine of decimalAngle. The hyperbolic cosine of d is defined to be (ex + e-x)/2 where e is Euler’s number.
-
Returns the hyperbolic cosine of doubleAngle. The hyperbolic cosine of d is defined to be (ex + e-x)/2 where e is Euler’s number.
-
Returns Euler’s number e raised to the power of the specified Decimal.
-
Returns Euler’s number e raised to the power of the specified Double.
-
Returns the largest (closest to positive infinity) Decimal that is not greater than the argument and is equal to a mathematical integer.
-
Returns the largest (closest to positive infinity) Double that is not greater than the argument and is equal to a mathematical integer.
-
Returns the natural logarithm (base e) of the specified Decimal.
-
Returns the natural logarithm (base e) of the specified Double.
-
Returns the logarithm (base 10) of the specified Decimal.
-
Returns the logarithm (base 10) of the specified Double.
-
max(decimalValue1, decimalValue2)
Returns the larger of the two specified Decimals.
-
max(doubleValue1, doubleValue2)
Returns the larger of the two specified Doubles.
-
max(integerValue1, integerValue2)
Returns the larger of the two specified Integers.
-
Returns the larger of the two specified Longs.
-
min(decimalValue1, decimalValue2)
Returns the smaller of the two specified Decimals.
-
min(doubleValue1, doubleValue2)
Returns the smaller of the two specified Doubles.
-
min(integerValue1, integerValue2)
Returns the smaller of the two specified Integers.
-
Returns the smaller of the two specified Longs.
-
mod(integerValue1, integerValue2)
Returns the remainder of integerValue1 divided by integerValue2.
-
Returns the remainder of longValue1 divided by longValue2.
-
Returns the value of the first Double raised to the power of exponent.
-
Returns a positive Double that is greater than or equal to 0.0 and less than 1.0.
-
Returns the value that is closest in value to decimalValue and is equal to a mathematical integer.
-
Returns the value that is closest in value to doubleValue and is equal to a mathematical integer.
-
Do not use. This method is deprecated as of the Winter ‘08 release. Instead, use
Math.roundToLong. Returns the closest Integer to the specified Double. If the result is less than -2,147,483,648 or greater than 2,147,483,647, Apex generates an error. -
Returns the rounded approximation of this Decimal. The number is rounded to zero decimal places using half-even rounding mode, that is, it rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case, this mode rounds towards the even neighbor. If the result is less than -2,147,483,648 or greater than 2,147,483,647, Apex generates an error.
-
Returns the rounded approximation of this Decimal. The number is rounded to zero decimal places using half-even rounding mode, that is, it rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case, this mode rounds towards the even neighbor.
-
Returns the closest Long to the specified Double.
-
Returns the signum function of the specified Decimal, which is 0 if decimalValue is 0, 1.0 if decimalValue is greater than 0, -1.0 if decimalValue is less than 0.
-
Returns the signum function of the specified Double, which is 0 if doubleValue is 0, 1.0 if doubleValue is greater than 0, -1.0 if doubleValue is less than 0.
-
Returns the trigonometric sine of the angle specified by decimalAngle.
-
Returns the trigonometric sine of the angle specified by doubleAngle.
-
Returns the hyperbolic sine of decimalAngle. The hyperbolic sine of decimalAngle is defined to be (ex - e-x)/2 where e is Euler’s number.
-
Returns the hyperbolic sine of doubleAngle. The hyperbolic sine of doubleAngle is defined to be (ex - e-x)/2 where e is Euler’s number.
-
Returns the correctly rounded positive square root of decimalValue.
-
Returns the correctly rounded positive square root of doubleValue.
-
Returns the trigonometric tangent of the angle specified by decimalAngle.
-
Returns the trigonometric tangent of the angle specified by doubleAngle.
-
Returns the hyperbolic tangent of decimalAngle. The hyperbolic tangent of decimalAngle is defined to be (ex - e-x)/(ex + e-x) where e is Euler’s number. In other words, it is equivalent to
sinh(x)/cosinh(x). The absolute value of the exacttanhis always less than 1. -
Returns the hyperbolic tangent of doubleAngle. The hyperbolic tangent of doubleAngle is defined to be (ex - e-x)/(ex + e-x) where e is Euler’s number. In other words, it is equivalent to
sinh(x)/cosinh(x). The absolute value of the exacttanhis always less than 1.
Returns the absolute value of the specified Decimal.
public static Decimal abs(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the absolute value of the specified Double.
public static Double abs(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the absolute value of the specified Integer.
public static Integer abs(Integer integerValue)
-
integerValue:
Type: Integer
Type: Integer
Returns the absolute value of the specified Long.
public static Long abs(Long longValue)
-
longValue:
Type: Long
Type: Long
Returns the arc cosine of an angle, in the range of 0.0 through pi.
public static Decimal acos(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the arc cosine of an angle, in the range of 0.0 through pi.
public static Double acos(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
public static Decimal asin(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the arc sine of an angle, in the range of -pi/2 through pi/2.
public static Double asin(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
public static Decimal atan(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the arc tangent of an angle, in the range of -pi/2 through pi/2.
public static Double atan(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Converts rectangular coordinates (xCoordinate and yCoordinate) to polar (r and theta). This method computes the phase theta by computing an arc tangent of xCoordinate/yCoordinate in the range of -pi to pi.
public static Decimal atan2(Decimal xCoordinate, Decimal yCoordinate)
Type: Decimal
Converts rectangular coordinates (xCoordinate and yCoordinate) to polar (r and theta). This method computes the phase theta by computing an arc tangent of xCoordinate/yCoordinate in the range of -pi to pi.
public static Double atan2(Double xCoordinate, Double yCoordinate)
Type: Double
Returns the cube root of the specified Decimal. The cube root of a negative value is the negative of the cube root of that value’s magnitude.
public static Decimal cbrt(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the cube root of the specified Double. The cube root of a negative value is the negative of the cube root of that value’s magnitude.
public static Double cbrt(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the smallest (closest to negative infinity) Decimal that is not less than the argument and is equal to a mathematical integer.
public static Decimal ceil(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the smallest (closest to negative infinity) Double that is not less than the argument and is equal to a mathematical integer.
public static Double ceil(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the trigonometric cosine of the angle specified by decimalAngle.
public static Decimal cos(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the trigonometric cosine of the angle specified by doubleAngle.
public static Double cos(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the hyperbolic cosine of decimalAngle. The hyperbolic cosine of d is defined to be (ex + e-x)/2 where e is Euler’s number.
public static Decimal cosh(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the hyperbolic cosine of doubleAngle. The hyperbolic cosine of d is defined to be (ex + e-x)/2 where e is Euler’s number.
public static Double cosh(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns Euler’s number e raised to the power of the specified Decimal.
public static Decimal exp(Decimal exponentDecimal)
-
exponentDecimal:
Type: Decimal
Type: Decimal
Returns Euler’s number e raised to the power of the specified Double.
public static Double exp(Double exponentDouble)
-
exponentDouble:
Type: Double
Type: Double
Returns the largest (closest to positive infinity) Decimal that is not greater than the argument and is equal to a mathematical integer.
public static Decimal floor(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the largest (closest to positive infinity) Double that is not greater than the argument and is equal to a mathematical integer.
public static Double floor(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the natural logarithm (base e) of the specified Decimal.
public static Decimal log(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the natural logarithm (base e) of the specified Double.
public static Double log(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the logarithm (base 10) of the specified Decimal.
public static Decimal log10(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the logarithm (base 10) of the specified Double.
public static Double log10(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the larger of the two specified Decimals.
public static Decimal max(Decimal decimalValue1, Decimal decimalValue2)
Type: Decimal
Returns the larger of the two specified Doubles.
public static Double max(Double doubleValue1, Double doubleValue2)
Type: Double
Returns the larger of the two specified Integers.
public static Integer max(Integer integerValue1, Integer integerValue2)
Type: Integer
Returns the larger of the two specified Longs.
public static Long max(Long longValue1, Long longValue2)
Type: Long
Returns the smaller of the two specified Decimals.
public static Decimal min(Decimal decimalValue1, Decimal decimalValue2)
Type: Decimal
Returns the smaller of the two specified Doubles.
public static Double min(Double doubleValue1, Double doubleValue2)
Type: Double
Returns the smaller of the two specified Integers.
public static Integer min(Integer integerValue1, Integer integerValue2)
Type: Integer
Returns the smaller of the two specified Longs.
public static Long min(Long longValue1, Long longValue2)
Type: Long
Returns the remainder of integerValue1 divided by integerValue2.
public static Integer mod(Integer integerValue1, Integer integerValue2)
Type: Integer
Returns the remainder of longValue1 divided by longValue2.
public static Long mod(Long longValue1, Long longValue2)
Type: Long
Returns the value of the first Double raised to the power of exponent.
public static Double pow(Double doubleValue, Double exponent)
Type: Double
Returns a positive Double that is greater than or equal to 0.0 and less than 1.0.
public static Double random()
Type: Double
Returns the value that is closest in value to decimalValue and is equal to a mathematical integer.
public static Decimal rint(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the value that is closest in value to doubleValue and is equal to a mathematical integer.
public static Double rint(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Do not use. This method is deprecated as of the Winter ‘08 release. Instead, use Math.roundToLong. Returns the closest Integer to the specified Double. If the result is less than -2,147,483,648 or greater than 2,147,483,647, Apex generates an error.
public static Integer round(Double doubleValue)
-
doubleValue:
Type: Double
Type: Integer
Returns the rounded approximation of this Decimal. The number is rounded to zero decimal places using half-even rounding mode, that is, it rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case, this mode rounds towards the even neighbor. If the result is less than -2,147,483,648 or greater than 2,147,483,647, Apex generates an error.
public static Integer round(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Integer
Note that this rounding mode statistically minimizes cumulative error when applied repeatedly over a sequence of calculations.
Returns the rounded approximation of this Decimal. The number is rounded to zero decimal places using half-even rounding mode, that is, it rounds towards the “nearest neighbor” unless both neighbors are equidistant, in which case, this mode rounds towards the even neighbor.
public static Long roundToLong(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Long
Note that this rounding mode statistically minimizes cumulative error when applied repeatedly over a sequence of calculations.
Returns the closest Long to the specified Double.
public static Long roundToLong(Double doubleValue)
-
doubleValue:
Type: Double
Type: Long
Returns the signum function of the specified Decimal, which is 0 if decimalValue is 0, 1.0 if decimalValue is greater than 0, -1.0 if decimalValue is less than 0.
public static Decimal signum(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the signum function of the specified Double, which is 0 if doubleValue is 0, 1.0 if doubleValue is greater than 0, -1.0 if doubleValue is less than 0.
public static Double signum(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the trigonometric sine of the angle specified by decimalAngle.
public static Decimal sin(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the trigonometric sine of the angle specified by doubleAngle.
public static Double sin(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the hyperbolic sine of decimalAngle. The hyperbolic sine of decimalAngle is defined to be (ex - e-x)/2 where e is Euler’s number.
public static Decimal sinh(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the hyperbolic sine of doubleAngle. The hyperbolic sine of doubleAngle is defined to be (ex - e-x)/2 where e is Euler’s number.
public static Double sinh(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the correctly rounded positive square root of decimalValue.
public static Decimal sqrt(Decimal decimalValue)
-
decimalValue:
Type: Decimal
Type: Decimal
Returns the correctly rounded positive square root of doubleValue.
public static Double sqrt(Double doubleValue)
-
doubleValue:
Type: Double
Type: Double
Returns the trigonometric tangent of the angle specified by decimalAngle.
public static Decimal tan(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the trigonometric tangent of the angle specified by doubleAngle.
public static Double tan(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double
Returns the hyperbolic tangent of decimalAngle. The hyperbolic tangent of decimalAngle is defined to be (ex - e-x)/(ex + e-x) where e is Euler’s number. In other words, it is equivalent to sinh(x)/cosinh(x). The absolute value of the exact tanh is always less than 1.
public static Decimal tanh(Decimal decimalAngle)
-
decimalAngle:
Type: Decimal
Type: Decimal
Returns the hyperbolic tangent of doubleAngle. The hyperbolic tangent of doubleAngle is defined to be (ex - e-x)/(ex + e-x) where e is Euler’s number. In other words, it is equivalent to sinh(x)/cosinh(x). The absolute value of the exact tanh is always less than 1.
public static Double tanh(Double doubleAngle)
-
doubleAngle:
Type: Double
Type: Double