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