• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 431
  • Last Modified:

NaN error when converting vba to java

Hi,

Im finally running the project that was converted from vba to java unfortunately i'm not receiving the proper output. This is because vba seems alot more tolerant of using '0's in equations than java does. eg

vba:
dcr = 1 / (1 + dcrp1 * Exp(dcrp2 * Exp(0.5 * (MAsy(1) - MAsy(0)) / MAsy(0)) _
    * diff * mom(s0, s1, g0, g1, 0, 0, serv, l1, l2)))

java:
CONSTANTS.setDcr(1 / (1 + CONSTANTS.getDcrp1() * Math.exp(CONSTANTS.getDcrp2() * Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
                * CONSTANTS.getDiff() * ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2])));

in both sitautions the array 'mom' for the given indexs is 0, however the vba version assigns a value to dcr whereas the java versions makes dcr 'NaN'

I understand what the problem is but cant (in my situation) think of a solution (except rewriting the whole code which is pretty much a nono because its not my logic and i dont really understand it and there's thousands of lines)

Any suggestions much appreciated
0
billyleo
Asked:
billyleo
  • 3
  • 2
  • 2
1 Solution
 
RishadanPortCommented:
Are you sure there isn't a problem in one of the function calls to retreive certain variables? Unlike in your VBA code where you reference the variable directly, in your Java code, you are making function calls to retreives the data.

-->CONSTANTS.setDcr(..)

-->CONSTANTS.getDcrp1()

-->CONSTANTS.getDcrp2()

-->CONSTANTS.getDiff()

Also another difference is this part:

ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]

here it is treating momArray directly as a 9 dimensional array, while the VBA code is a function call.
0
 
RishadanPortCommented:
>Im finally running the project that was converted from vba to java unfortunately i'm not receiving the >proper output. This is because vba seems alot more tolerant of using '0's in equations than java does.

I highly doubt that this is the case. I am quite sure that your conversation that has been translated into java has some errors in it
0
 
Peter KwanCommented:
Please check for each of the components return correct values and data type:

CONSTANTS.getDcrp1()
CONSTANTS.getDcrp2()
ARRAYS.MAsy[1]
ARRAYS.MAsy[0]
CONSTANTS.getDiff()
ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]

Especially the following:
ARRAYS.MAsy[0] = 0 ?
ARRAYS.MAsy[1]-ARRAYS.MAsy[0] = 0?
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Peter KwanCommented:
Since one of the way that would cause your value of dcr is NaN is this expression:
Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])

when
ARRAYS.MAsy[1] = ARRAYS.MAsy[0] = 0
0
 
billyleoAuthor Commented:
CONSTANTS.getDcrp1() returns correct value - in the current case - 0.074881

CONSTANTS.getDcrp2() - 3.830579999999994

CONSTANTS.getDiff()  - 0.1

ARRAYS.MAsy[1] - 2
ARRAYS.MAsy[0] - 2

ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2]  is usually 0 but i changed it to 1^-9

but these are the same values in the vba version and a definite value is produced!
0
 
Peter KwanCommented:
I have tested your values, it should be outputting a value (0.93...).

Since your expression is quite complex, you may try to print out the values of :

Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
 Math.exp(CONSTANTS.getDcrp2() * Math.exp(0.5 * (ARRAYS.MAsy[1] - ARRAYS.MAsy[0]) / ARRAYS.MAsy[0])
                * CONSTANTS.getDiff() * ARRAYS.momARRAY[s0][s1][g0][g1][0][0][serv][l1][l2])

to debug yourself. If you still have problems, please post your complete code.
0
 
billyleoAuthor Commented:
Thanks for the help - you were right the Nan reference is coming from some other part of the code - now to trawl through 6000+ lines and 3000 + iterations to find it.

Yippee
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now