mirror of
https://gitee.com/dromara/hutool.git
synced 2025-04-05 17:37:59 +08:00
fix equals
This commit is contained in:
parent
69362f1031
commit
c59acb3bac
@ -10,6 +10,7 @@
|
||||
* 【http 】 HttpRequest增加setProxy重载(pr#190@Gitee)
|
||||
* 【core 】 XmlUtil.cleanComment(pr#191@Gitee)
|
||||
* 【core 】 ArrayUtil.unWrap增加默认值(pr#1149@Github)
|
||||
* 【core 】 ArrayUtil.indexOf修改double的equals判断(pr#1147@Github)
|
||||
|
||||
### Bug修复
|
||||
* 【core 】 解决农历判断节日未判断大小月导致的问题(issue#I1XHSF@Gitee)
|
||||
|
@ -1613,7 +1613,7 @@ public class ArrayUtil {
|
||||
public static int indexOf(double[] array, double value) {
|
||||
if (null != array) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (value == array[i]) {
|
||||
if (NumberUtil.equals(value, array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -1632,7 +1632,7 @@ public class ArrayUtil {
|
||||
public static int lastIndexOf(double[] array, double value) {
|
||||
if (null != array) {
|
||||
for (int i = array.length - 1; i >= 0; i--) {
|
||||
if (value == array[i]) {
|
||||
if (NumberUtil.equals(value, array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -1663,7 +1663,7 @@ public class ArrayUtil {
|
||||
public static int indexOf(float[] array, float value) {
|
||||
if (null != array) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (value == array[i]) {
|
||||
if (NumberUtil.equals(value, array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
@ -1682,7 +1682,7 @@ public class ArrayUtil {
|
||||
public static int lastIndexOf(float[] array, float value) {
|
||||
if (null != array) {
|
||||
for (int i = array.length - 1; i >= 0; i--) {
|
||||
if (value == array[i]) {
|
||||
if (NumberUtil.equals(value, array[i])) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
@ -1712,7 +1712,7 @@ public class NumberUtil {
|
||||
|
||||
/**
|
||||
* 比较大小,值相等 返回true<br>
|
||||
* 此方法通过调用{@link BigDecimal#compareTo(BigDecimal)}方法来判断是否相等<br>
|
||||
* 此方法通过调用{@link Double#doubleToLongBits(double)}方法来判断是否相等<br>
|
||||
* 此方法判断值相等时忽略精度的,即0.00 == 0
|
||||
*
|
||||
* @param num1 数字1
|
||||
@ -1721,7 +1721,21 @@ public class NumberUtil {
|
||||
* @since 5.4.2
|
||||
*/
|
||||
public static boolean equals(double num1, double num2) {
|
||||
return equals(toBigDecimal(num1), toBigDecimal(num2));
|
||||
return Double.doubleToLongBits(num1) == Double.doubleToLongBits(num2);
|
||||
}
|
||||
|
||||
/**
|
||||
* 比较大小,值相等 返回true<br>
|
||||
* 此方法通过调用{@link Double#doubleToLongBits(double)}方法来判断是否相等<br>
|
||||
* 此方法判断值相等时忽略精度的,即0.00 == 0
|
||||
*
|
||||
* @param num1 数字1
|
||||
* @param num2 数字2
|
||||
* @return 是否相等
|
||||
* @since 5.4.5
|
||||
*/
|
||||
public static boolean equals(float num1, float num2) {
|
||||
return Float.floatToIntBits(num1) == Float.floatToIntBits(num2);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -263,10 +263,10 @@ public class NumberUtilTest {
|
||||
|
||||
@Test
|
||||
public void isPowerOfTwoTest() {
|
||||
Assert.assertEquals(false, NumberUtil.isPowerOfTwo(-1));
|
||||
Assert.assertEquals(true, NumberUtil.isPowerOfTwo(16));
|
||||
Assert.assertEquals(true, NumberUtil.isPowerOfTwo(65536));
|
||||
Assert.assertEquals(true, NumberUtil.isPowerOfTwo(1));
|
||||
Assert.assertEquals(false, NumberUtil.isPowerOfTwo(17));
|
||||
Assert.assertFalse(NumberUtil.isPowerOfTwo(-1));
|
||||
Assert.assertTrue(NumberUtil.isPowerOfTwo(16));
|
||||
Assert.assertTrue(NumberUtil.isPowerOfTwo(65536));
|
||||
Assert.assertTrue(NumberUtil.isPowerOfTwo(1));
|
||||
Assert.assertFalse(NumberUtil.isPowerOfTwo(17));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user