[ 
https://issues.apache.org/jira/browse/LANG-1615?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Arturo Bernal updated LANG-1615:
--------------------------------
    Description: 
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}
 

  was:
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}
 


> ArrayUtils contains && 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
>            Priority: Major
>              Labels: pull-request-available
>
> 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)

Reply via email to