[ 
https://issues.apache.org/jira/browse/LANG-1646?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17296058#comment-17296058
 ] 

Alex Herbert commented on LANG-1646:
------------------------------------

Upon further investigation recognition of zero uses the value of the exponent. 
This does not matter if the magnitude is zero.

This passes:
{code:java}
        assertEquals(0.0, Double.parseDouble("0.0e-2000"));
        assertTrue(NumberUtils.isCreatable("0.0e-2000"));
{code}
These all fail:
{code:java}
        assertEquals(Float.valueOf(0.0), NumberUtils.createNumber("0.0e-2000"));
        assertEquals(Float.valueOf(0.0), 
NumberUtils.createNumber("0.0e-2000F"));
        assertEquals(Double.valueOf(0.0), 
NumberUtils.createNumber("0.0e-2000D"));
{code}
So method must check the magnitude is zero but ignore the exponent. This will 
allow it to return a number when isCreatable returns true.

 

> NumberUtils fails to create requested type for floating point zero
> ------------------------------------------------------------------
>
>                 Key: LANG-1646
>                 URL: https://issues.apache.org/jira/browse/LANG-1646
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.12.0
>            Reporter: Alex Herbert
>            Assignee: Alex Herbert
>            Priority: Trivial
>
> This currently fails:
> {code:java}
>         assertEquals(Float.valueOf(0), NumberUtils.createNumber("0F"));
>         assertEquals(Double.valueOf(0), NumberUtils.createNumber("0D"));
> {code}
> This passes:
> {code:java}
>         assertEquals(Float.valueOf(0), NumberUtils.createNumber("0.F"));
>         assertEquals(Double.valueOf(0), NumberUtils.createNumber("0.D"));
>         assertEquals(Float.valueOf(0), NumberUtils.createNumber("0e0F"));
>         assertEquals(Double.valueOf(0), NumberUtils.createNumber("0e0D"));
> {code}
> This is due to the incorrect extraction of the mantissa for a floating point 
> value when there is no exponent or decimal place as it includes the trailing 
> format specifier (F or D). The input string is then not detected as being all 
> zeros and the returned type is BigDecimal.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to