Stupid math problem

This used to work. I have no idea how YY ends-up being a "method" (function pointer).

try {

var XX = Math.cos(radLat1) * Math.sin(radLat2) - Math.sin(radLat1) * Math.cos(radLat2) * Math.cos(radLonDelta);
System.println("XX="+XX);
var YY1 = Math.sin(radLonDelta.toDouble());
System.println("YY1="+YY1);
var YY2 = Math.cos(radLat2.toDouble());
System.println("YY2="+YY2);
var YY = YY1.toDouble() * YY2.toDouble();
System.println("YY="+YY);

var ZZ = Math.atan2(YY, XX); // Reversed argument order than in Excel.
System.println("ccc3");

// bearing = (Math.toDegrees(ZZ).toLong()+360) % 360;
}

ccc
XX=-0.002073
YY1=0.000449
YY2=0.755157
YY=method
Cannot convert object to Double
Invalid Value

  • It sort of looks like functions can't be too big. I am doing two "complicate" calculations. Before, I did them separately. Combining them caused this and other weird problems. Splitting them back up seems not to produce the same problem.
  • It looks like you have encountered a bug of some sort, but I"m not able to reproduce by pasting the code into an existing application.

    If you are able, it would be helpful if you could provide the necessary bits of information so that we may be able to reproduce and fix it.This thread lists the bits of information we'd like, in this case the most important bit will be a test case.
  • I suspect the function ran out of stack space.

    The code was originally split into two functions. I combined the code into one function. That worked. When I added a little more code, this problem occurred. Splitting the code made it go away.

    It probably would take a couple of hours to create a demo app that isolates the problem.
  • I believe that if you run out of stack space, the app should get stack overflow error, not an invalid value.
  • I think you misinterpreted my last post. That isn't a fix we want to make; the virtual machine already has code in place to detect stack overflow and it is supposed to generate a stack overflow error when this happens. We already have tests in place to verify it is working.

    If you were actually overflowing the stack, I'd expect you'd get the stack overflow message instead of the odd behavior you're seeing. So either your code is not overflowing the stack and something else is going on, or the stack overflow detection isn't perfect and needs to be re-examined. Without a test case it will be difficult to tell.

    While it is preferred, you don't necessarily need to create a test case from scratch. If you can re-create the bug in your app, you should be able to send us the the source (instructions for doing so are in the thread I linked to previously).