Merge branch 'v5-dev' into v5-dev

This commit is contained in:
Golden Looly
2025-12-09 16:38:24 +08:00
committed by GitHub
5 changed files with 41 additions and 6 deletions

View File

@@ -1,12 +1,13 @@
# 🚀Changelog
-------------------------------------------------------------------------------------------------------------
# 5.8.43(2025-12-01)
# 5.8.43(2025-12-09)
### 🐣新特性
* 【core 】 `ColorUtil`颜色名称DARKGOLD、LIGHTGOLD新增蛇形命名匹配pr#1400@Github
### 🐞Bug修复
* 【core 】 修复`Calculator.conversion(String expression)`方法计算包含科学计数法表达式的值时逻辑有误结果不符合预期pr#4172@Github
* 【core 】 修复`Calculator.conversion`方法计算包含科学计数法表达式的值时逻辑有误结果不符合预期pr#4172@Github
* 【core 】 修复`NumberUtil.getBinaryStr`方法计算Double等丢失小数问题pr#1411@Gitee
-------------------------------------------------------------------------------------------------------------
# 5.8.42(2025-11-28)

View File

@@ -360,6 +360,9 @@ public class ListUtil {
* @since 4.0.6
*/
public static <T> List<T> reverseNew(List<T> list) {
if (list == null) {
return null;
}
List<T> list2 = ObjectUtil.clone(list);
if (null == list2) {
// 不支持clone

View File

@@ -1705,15 +1705,39 @@ public class NumberUtil {
/**
* 获得数字对应的二进制字符串
* <ul>
* <li>Integer/Long直接使用 JDK 内置方法转换</li>
* <li>Byte/Short转换为无符号整数后补充前导零至对应位数Byte=8位Short=16位</li>
* <li>Float/Double使用 IEEE 754 标准格式转换Float=32位Double=64位</li>
* </ul>
*
* @param number 数字
* @return 二进制字符串
*/
public static String getBinaryStr(Number number) {
if (number instanceof Long) {
Assert.notNull(number, "Number must be not null!");
if (number instanceof Double) {
// 处理double类型
long bits = Double.doubleToLongBits((Double) number);
return String.format("%64s", Long.toBinaryString(bits)).replace(' ', '0');
} else if (number instanceof Float) {
// 处理float类型
int bits = Float.floatToIntBits((Float) number);
return String.format("%32s", Integer.toBinaryString(bits)).replace(' ', '0');
}else if (number instanceof Long) {
return Long.toBinaryString((Long) number);
} else if (number instanceof Integer) {
return Integer.toBinaryString((Integer) number);
} else if (number instanceof Byte) {
// Byte是8位补前导0至8位
return String.format("%8s", Integer.toBinaryString(number.byteValue() & 0xFF)).replace(' ', '0');
} else if (number instanceof Short) {
// Short是16位补前导0至16位
return String.format("%16s", Integer.toBinaryString(number.shortValue() & 0xFFFF)).replace(' ', '0');
} else if (number instanceof BigInteger) {
// 大数整数类型
return ((BigInteger) number).toString(2);
} else {
return Long.toBinaryString(number.longValue());
}

View File

@@ -715,5 +715,12 @@ public class NumberUtilTest {
int result = NumberUtil.multiple(a, b);
// 验证结果必须是正数(两个正数的最小公倍数必须为正)
assertTrue(result > 0);
}
@Test
public void testGetFloatBinaryStr() {
// 获取浮点数的 IEEE 754 原始比特位字符串
final String result = NumberUtil.getBinaryStr(3.5);
assertEquals("0100000000001100000000000000000000000000000000000000000000000000", result);
}
}

View File

@@ -462,14 +462,14 @@
<dependency>
<groupId>org.mozilla</groupId>
<artifactId>rhino</artifactId>
<version>1.7.14</version>
<version>1.7.15.1</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>QLExpress</artifactId>
<version>3.3.3</version>
<version>3.3.4</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>
@@ -477,7 +477,7 @@
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-compress</artifactId>
<version>1.26.0</version>
<version>1.28.0</version>
<scope>compile</scope>
<optional>true</optional>
</dependency>