commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Yannick TANGUY (JIRA)" <j...@apache.org>
Subject [jira] [Updated] (MATH-658) Dead code in FastMath.pow(double, double) and some improvement in test coverage
Date Tue, 06 Sep 2011 09:34:11 GMT

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

Yannick TANGUY updated MATH-658:
--------------------------------

    Description: 
This issue concerns the FastMath class and its test class.

(1) In the double pow(double, double) function, there are 2 identical "if" blocks. The second
one can be suppressed.
                if (y < 0 && y == yi && (yi & 1) == 1) {
                    return Double.NEGATIVE_INFINITY;
                }

                // this block is never used -> to be suppressed
                if (y < 0 && y == yi && (yi & 1) == 1) {
                    return -0.0;
                }

                if (y > 0 && y == yi && (yi & 1) == 1) {
                    return -0.0;
                }


(2) To obtain better code coverage, we added some tests case in FastMathTest.java (see attached
file)
- Added test for log1p
- Added tests in testPowSpecialCases()
- Added tests for a 100% coverage of acos().
- Added tests for a 100% coverage of asin().


  was:
This issue concerns the FastMath class and its test class.
I don't know how to attach source code to an issue : sorry if it's not easy to read...

(1) In the double pow(double, double) function, there are 2 identical "if" blocks. The second
one can be suppressed.
                if (y < 0 && y == yi && (yi & 1) == 1) {
                    return Double.NEGATIVE_INFINITY;
                }

                // this block is never used -> to be suppressed
                if (y < 0 && y == yi && (yi & 1) == 1) {
                    return -0.0;
                }

                if (y > 0 && y == yi && (yi & 1) == 1) {
                    return -0.0;
                }


(2) To obtain better code coverage, we added some tests case in FastMathTest.java : 

    /**
     * Added test for log1p
     */
    @Test
    public void testLog1pSpecialCases() {
        double x;
        
    	x = FastMath.log1p(-1.0);
        if (x != Double.NEGATIVE_INFINITY)
            throw new RuntimeException("Log1p of -1 should be -infinity");

    }

  public void testPowSpecialCases() {
 

  // [ ... ]


       // Added tests for a 100% coverage
             
        x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN);
        if (x == x)
            throw new RuntimeException("pow(+Inf, NaN) should be NaN");
        
        x = FastMath.pow(Double.POSITIVE_INFINITY, Double.NaN);
        if (x == x)
            throw new RuntimeException("pow(+Inf, NaN) should be NaN");
        
        x = FastMath.pow(1.0, Double.POSITIVE_INFINITY);
        if (x == x)
            throw new RuntimeException("pow(1.0, +Inf) should be NaN");
        
        x = FastMath.pow(Double.NEGATIVE_INFINITY, Double.NaN);
        if (x == x)
            throw new RuntimeException("pow(-Inf, NaN) should be NaN");
        
        x = FastMath.pow(Double.NEGATIVE_INFINITY, -1.0);
        if (x != -0.0)
            throw new RuntimeException("pow(-Inf, -1.0) should be 0.0");
        
        x = FastMath.pow(Double.NEGATIVE_INFINITY, -2.0);
        if (x != 0.0)
            throw new RuntimeException("pow(-Inf, -2.0) should be 0.0");
    
        x = FastMath.pow(Double.NEGATIVE_INFINITY, 1.0);
        if (x != Double.NEGATIVE_INFINITY)
            throw new RuntimeException("pow(-Inf, 1.0) should be -Inf");
        
        x = FastMath.pow(Double.NEGATIVE_INFINITY, 2.0);
        if (x != Double.POSITIVE_INFINITY)
            throw new RuntimeException("pow(-Inf, 2.0) should be +Inf");

        x = FastMath.pow(1.0, Double.NEGATIVE_INFINITY);
        if (x == x)
           throw new RuntimeException("pow(1.0, -Inf) should be NaN");

   }
     
    /**
     * Added tests for a 100% coverage of acos().
     */
    @Test
    public void testAcosSpecialCases() {
    	double x;

    	x = FastMath.acos(Double.NaN);
    	if (x == x)
    		throw new RuntimeException("acos(NaN) should NaN");

    	x = FastMath.acos(-1.1);
    	if (x == x)
    		throw new RuntimeException("acos(-1.1) should NaN");
    	
    	x = FastMath.acos(1.1);
    	if (x == x)
    		throw new RuntimeException("acos(-1.1) should NaN");
   
    	assertEquals(FastMath.acos(-1.0), FastMath.PI, Double.MIN_VALUE);

    	assertEquals(FastMath.acos(1.0), 0.0, Double.MIN_VALUE);

    	assertEquals(FastMath.acos(0.0), FastMath.PI / 2.0, Double.MIN_VALUE);
    }
    
    /**
     * Added tests for a 100% coverage of asin().
     */
    @Test
    public void testAsinSpecialCases() {
    	double x;

    	x = FastMath.asin(Double.NaN);
    	if (x == x)
    		throw new RuntimeException("asin(NaN) should NaN");

    	x = FastMath.asin(-1.1);
    	if (x == x)
    		throw new RuntimeException("asin(-1.1) should NaN");
    	
    	x = FastMath.asin(1.1);
    	if (x == x)
    		throw new RuntimeException("asin(-1.1) should NaN");
   
    	assertEquals(FastMath.asin(1.0), FastMath.PI / 2.0, Double.MIN_VALUE);

    	assertEquals(FastMath.asin(-1.0), -FastMath.PI / 2.0, Double.MIN_VALUE);

    	assertEquals(FastMath.asin(0.0), 0.0, Double.MIN_VALUE);
    }
    
 

 


> Dead code in FastMath.pow(double, double) and some improvement in test coverage
> -------------------------------------------------------------------------------
>
>                 Key: MATH-658
>                 URL: https://issues.apache.org/jira/browse/MATH-658
>             Project: Commons Math
>          Issue Type: Improvement
>            Reporter: Yannick TANGUY
>            Priority: Minor
>             Fix For: 3.0
>
>         Attachments: FastMathTest.java
>
>
> This issue concerns the FastMath class and its test class.
> (1) In the double pow(double, double) function, there are 2 identical "if" blocks. The
second one can be suppressed.
>                 if (y < 0 && y == yi && (yi & 1) == 1) {
>                     return Double.NEGATIVE_INFINITY;
>                 }
>                 // this block is never used -> to be suppressed
>                 if (y < 0 && y == yi && (yi & 1) == 1) {
>                     return -0.0;
>                 }
>                 if (y > 0 && y == yi && (yi & 1) == 1) {
>                     return -0.0;
>                 }
> (2) To obtain better code coverage, we added some tests case in FastMathTest.java (see
attached file)
> - Added test for log1p
> - Added tests in testPowSpecialCases()
> - Added tests for a 100% coverage of acos().
> - Added tests for a 100% coverage of asin().

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

        

Mime
View raw message