commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Luc Maisonobe (JIRA)" <j...@apache.org>
Subject [jira] [Resolved] (MATH-567) class Dfp toDouble method return -inf whan Dfp value is 0 "zero"
Date Thu, 05 May 2011 19:45:03 GMT

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

Luc Maisonobe resolved MATH-567.
--------------------------------

       Resolution: Fixed
    Fix Version/s: 3.0

Fixed in subversion repository as of r1099938.

There were conversions problems in both directions! As you noticed, converting from Dfp to
double generated infinities, but creating new Dfp(-0.0) did not preserve the sign.

Thanks for the report and the hint for fixing the bug.

> class Dfp toDouble method return -inf whan Dfp value is 0 "zero"
> ----------------------------------------------------------------
>
>                 Key: MATH-567
>                 URL: https://issues.apache.org/jira/browse/MATH-567
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: michel
>            Priority: Minor
>             Fix For: 3.0
>
>
> I found a bug in the toDouble() method of the Dfp class.
> If the Dfp's value is 0 "zero", the toDouble() method returns a  negative infini.
> This is because the double value returned has an exposant equal to 0xFFF 
> and a significand is equal to 0.
> In the IEEE754 this is a -inf.
> To be equal to zero, the exposant and the significand must be equal to zero.
> A simple test case is :
> ----------------------------------------------
> import org.apache.commons.math.dfp.DfpField;
> public class test {
> 	/**
> 	 * @param args
> 	 */
> 	public static void main(String[] args) {
> 		DfpField field = new DfpField(100);
> 		System.out.println("toDouble value of getZero() ="+field.getZero().toDouble()+
> 				"\ntoDouble value of newDfp(0.0) ="+
> 				field.newDfp(0.0).toDouble());
> 	}
> }
> May be the simplest way to fix it is to test the zero equality at the begin of the toDouble()
method, to be able to return the correctly signed zero ?

--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira

Mime
View raw message