Browse Source

fix numberUtil

Looly 5 years ago
parent
commit
ff10ea0d9c

+ 1 - 0
CHANGELOG.md

@@ -28,6 +28,7 @@
 * 【dfa    】     SensitiveUtil增加setCharFilter方法(pr#1123@Github)
 * 【all    】     优化常量大小写规范(pr#188@Gitee)
 * 【core   】     优化NumberUtil中针对BigDecimal的一些处理逻辑(pr#1127@Github)
+* 【core   】     NumberUtil.factorial注释明确(pr#1126@Github)
 
 ### Bug修复
 * 【crypto 】     修复SM2验签后无法解密问题(issue#I1W0VP@Gitee)

+ 4 - 4
hutool-core/src/main/java/cn/hutool/core/util/NumberUtil.java

@@ -1412,13 +1412,13 @@ public class NumberUtil {
 	// ------------------------------------------------------------------------------------------- others
 
 	/**
-	 * 计算阶乘
+	 * 计算范围阶乘
 	 * <p>
-	 * n! = n * (n-1) * ... * end
+	 * factorial(start, end) = start * (start - 1) * ... * (end - 1)
 	 * </p>
 	 *
-	 * @param start 阶乘起始
-	 * @param end   阶乘结束,必须小于起始
+	 * @param start 阶乘起始(包含)
+	 * @param end   阶乘结束,必须小于起始(不包括)
 	 * @return 结果
 	 * @since 4.1.0
 	 */

+ 2 - 0
hutool-core/src/test/java/cn/hutool/core/util/NumberUtilTest.java

@@ -245,6 +245,8 @@ public class NumberUtilTest {
 		Assert.assertEquals(120, factorial);
 		factorial = NumberUtil.factorial(5, 1);
 		Assert.assertEquals(120, factorial);
+
+		Assert.assertEquals(5, NumberUtil.factorial(5, 4));
 	}
 
 	@Test