javadoc.com.google.common.math.DoubleMath.html Maven / Gradle / Ivy
The newest version!
DoubleMath (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.math
Class DoubleMath
java.lang.Object
com.google.common.math.DoubleMath
@Beta
public final class DoubleMath
- extends Object
A class for arithmetic on doubles that is not covered by Math
.
- Since:
- 11.0
- Author:
- Louis Wasserman
Constructor Summary | |
---|---|
DoubleMath()
|
Method Summary | |
---|---|
static double |
factorial(int n)
Returns n! , that is, the product of the first n positive
integers, 1 if n == 0 , or e n!}, or
Double.POSITIVE_INFINITY if n! > Double.MAX_VALUE . |
static boolean |
isMathematicalInteger(double x)
Returns true if x represents a mathematical integer. |
static boolean |
isPowerOfTwo(double x)
Returns true if x is exactly equal to 2^k for some finite integer
k . |
static double |
log2(double x)
Returns the base 2 logarithm of a double value. |
static int |
log2(double x,
RoundingMode mode)
Returns the base 2 logarithm of a double value, rounded with the specified rounding mode to an int . |
static BigInteger |
roundToBigInteger(double x,
RoundingMode mode)
Returns the BigInteger value that is equal to x rounded with the specified
rounding mode, if possible. |
static int |
roundToInt(double x,
RoundingMode mode)
Returns the int value that is equal to x rounded with the specified rounding
mode, if possible. |
static long |
roundToLong(double x,
RoundingMode mode)
Returns the long value that is equal to x rounded with the specified rounding
mode, if possible. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
DoubleMath
public DoubleMath()
Method Detail |
---|
roundToInt
public static int roundToInt(double x, RoundingMode mode)
- Returns the
int
value that is equal tox
rounded with the specified rounding mode, if possible.- Throws:
ArithmeticException
- ifx
is infinite or NaNx
, after being rounded to a mathematical integer using the specified rounding mode, is either less thanInteger.MIN_VALUE
or greater thanInteger.MAX_VALUE
x
is not a mathematical integer andmode
isRoundingMode.UNNECESSARY
roundToLong
public static long roundToLong(double x, RoundingMode mode)
- Returns the
long
value that is equal tox
rounded with the specified rounding mode, if possible.- Throws:
ArithmeticException
- ifx
is infinite or NaNx
, after being rounded to a mathematical integer using the specified rounding mode, is either less thanLong.MIN_VALUE
or greater thanLong.MAX_VALUE
x
is not a mathematical integer andmode
isRoundingMode.UNNECESSARY
roundToBigInteger
public static BigInteger roundToBigInteger(double x, RoundingMode mode)
- Returns the
BigInteger
value that is equal tox
rounded with the specified rounding mode, if possible.- Throws:
ArithmeticException
- ifx
is infinite or NaNx
is not a mathematical integer andmode
isRoundingMode.UNNECESSARY
isPowerOfTwo
public static boolean isPowerOfTwo(double x)
- Returns
true
ifx
is exactly equal to2^k
for some finite integerk
.
log2
public static double log2(double x)
- Returns the base 2 logarithm of a double value.
Special cases:
- If
x
is NaN or less than zero, the result is NaN. - If
x
is positive infinity, the result is positive infinity. - If
x
is positive or negative zero, the result is negative infinity.
The computed result must be within 1 ulp of the exact result.
If the result of this method will be immediately rounded to an
int
,log2(double, RoundingMode)
is faster. - If
log2
public static int log2(double x, RoundingMode mode)
- Returns the base 2 logarithm of a double value, rounded with the specified rounding mode to an
int
.Regardless of the rounding mode, this is faster than
(int) log2(x)
.- Throws:
IllegalArgumentException
- ifx <= 0.0
,x
is NaN, orx
is infinite
isMathematicalInteger
public static boolean isMathematicalInteger(double x)
- Returns
true
ifx
represents a mathematical integer.This is equivalent to, but not necessarily implemented as, the expression
!Double.isNaN(x) && !Double.isInfinite(x) && x == Math.rint(x)
.
factorial
public static double factorial(int n)
- Returns
n!
, that is, the product of the firstn
positive integers,1
ifn == 0
, or e n!}, orDouble.POSITIVE_INFINITY
ifn! > Double.MAX_VALUE
.The result is within 1 ulp of the true value.
- Throws:
IllegalArgumentException
- ifn < 0
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.
© 2015 - 2025 Weber Informatics LLC | Privacy Policy