Menu

#68 CMO not handling divide by zero

closed-fixed
Bug (61)
7
2006-07-21
2006-02-19
No

Posted by: BarryTsung Posted on: February 08, 2006,
08:47:45 PM
Insert Quote
Mario,

Please run the following code.

Code:
package TA.Lib;

import java.util.Arrays;

public class TestCMO
{
public final static double FLT_EPSILON =
1.192092896e-07;
public final static double TA_REAL_MIN = (-3e+37);

public static void main(String[] args)
{
Core lib = new Core();

// initialize inputRandFltEpsilon
double[] inputRandFltEpsilon = new double[100];
for (int i = 0; i < inputRandFltEpsilon.length;
i++)
{
int sign = ((int) Math.random()) % 2;
double data = (sign != 0 ? 1.0 : -1.0) *
(FLT_EPSILON);
inputRandFltEpsilon[i]= data;
}
// set default integer input option
int optInTimePeriod = Integer.MIN_VALUE;

// set output buffer
double[] output = new double[100];
Arrays.fill(output, TA_REAL_MIN);

MInteger outBegIdx = new MInteger();
MInteger outNbElement = new MInteger();

TA_RetCode retCode = lib.CMO
(0,inputRandFltEpsilon.length-
1,inputRandFltEpsilon,optInTimePeriod,outBegIdx,outNbE
lement,output);

System.out.println
("outBegIdx="+outBegIdx.value+",outNbElement="+outNbEl
ement.value);

for(int i=0;i<output.length;i++)
{
System.out.println("["+i+"]="+output[i]);
}
}
}

The first element of result will be 0, and the rest
of result will be NaN.

Barry

Discussion

  • Mario Fortier

    Mario Fortier - 2006-02-19

    Logged In: YES
    user_id=1123

    Thanks Barry for reporting this bug.

    The CMO code was not detecting the divide by zero. It was
    not testing the right variable.

    This is now fix in CVS and will be part of the next 0.2
    release.

    \Mario

     
  • Mario Fortier

    Mario Fortier - 2006-07-21
    • status: open --> closed-fixed
     

Log in to post a comment.