[Guava使用教程]-数学运算
内容
- 基本的独立数学函数根据涉及的主要数字类型分为IntMath、LongMath、DoubleMath和BigIntegerMath。这些类具有并行结构,但每个类只支持函数的相关子集。请注意,在
com.google.common.primitives
类中也可以找到类似的函数,它们本质上不那么数学化。 - 为单个和成对的数据集提供了各种统计计算(平均值、中位数等)。从阅读本文开始,而不仅仅是浏览Javadoc。
- LinearTransformation 表示
y = mx + b
的两个值之间的线性变换; 例如,英尺和米之间的换算,或者凯尔文和摄氏温度之间的换算。
示例:
int logFloor = LongMath.log2(n, FLOOR);
int mustNotOverflow = IntMath.checkedMultiply(x, y);
long quotient = LongMath.divide(knownMultipleOfThree, 3, RoundingMode.UNNECESSARY); // fail fast on non-multiple of 3
BigInteger nearestInteger = DoubleMath.roundToBigInteger(d, RoundingMode.HALF_EVEN);
BigInteger sideLength = BigIntegerMath.sqrt(area, CEILING);