You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Gary D. Gregory (Jira)" <ji...@apache.org> on 2020/11/15 22:42:00 UTC
[jira] [Updated] (LANG-1615) ArrayUtils contains() and indexOf()
fails to handle Float.NaN
[ https://issues.apache.org/jira/browse/LANG-1615?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Gary D. Gregory updated LANG-1615:
----------------------------------
Summary: ArrayUtils contains() and indexOf() fails to handle Float.NaN (was: ArrayUtils contains && indexOf fails to handle Float.NaN)
> ArrayUtils contains() and indexOf() fails to handle Float.NaN
> --------------------------------------------------------------
>
> Key: LANG-1615
> URL: https://issues.apache.org/jira/browse/LANG-1615
> Project: Commons Lang
> Issue Type: Bug
> Affects Versions: 3.11
> Reporter: Arturo Bernal
> Assignee: Gary D. Gregory
> Priority: Major
> Labels: pull-request-available
> Time Spent: 1h
> Remaining Estimate: 0h
>
> The ArrayUtils.contains (float [], Float.NaN) and ArrayUtils.indexOf (float [], Float.NaN) methods do not handle correctly when the array contains Float.NaN. It should return that finds the element, but instead returns -1.
> For example, consider the following:
> {code:java}
> @Test
> public void testContainsFloatNaN() {
> float[] a = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY };
> assertTrue(ArrayUtils.contains(a, Float.POSITIVE_INFINITY));
> assertTrue(ArrayUtils.contains(a, Float.NEGATIVE_INFINITY));
> assertTrue(ArrayUtils.contains(a, Float.NaN)); // Error
> }{code}
>
> And
> {code:java}
> @Test
> public void testIndexOfFloatNaN() {
> float[] array = new float[] { Float.NEGATIVE_INFINITY, Float.NaN, Float.POSITIVE_INFINITY, Float.NaN };
> assertEquals(0, ArrayUtils.indexOf(array, Float.NEGATIVE_INFINITY));
> assertEquals(1, ArrayUtils.indexOf(array, Float.NaN)); // Error
> assertEquals(2, ArrayUtils.indexOf(array, Float.POSITIVE_INFINITY));
> }{code}
>
--
This message was sent by Atlassian Jira
(v8.3.4#803005)