Profile image

A question about overflow in funky trees

9,445 vcharng  4.2 years ago

I have found a formula in FT which is so good, it can accurately let you skip-bomb (well actually, more like a very fast torpedo) a moving ship from 10 km away.

But here's the problem: the formula only works in DebugExpression, it doesn't work when I apply the formula to a light or something.

It seems that number overflow is the problem here.
The formula uses the Pythagorean theorem to calculate the distance between the bomb and the target at the estimated impact time. And as such, it requires squaring the coordinates.
This makes the numbers very big, it could easily reach the millions, and as such, the funky trees fail to function.

I tried a lot of things, minimizing the number, square root, rounding, but none of them works.

Does anyone have some ways to avoid this issue?

  • Log in to leave a comment
  • Profile image
    9,445 vcharng

    @SnoWFLakE0s It's odd for me too.
    I've seen people making very complicated stuff with the beacon light, but I can't even make a light half as complicated as theirs.

    4.2 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @vcharng
    .
    Odd. I regularly use numbers on the magnitude of 10^5 and above; I haven't had this issue.

    4.2 years ago
  • Profile image
    9,445 vcharng

    @SnoWFLakE0s that code I posted is basically "returns 1 when the torpedo should hit within 50m of the target ship, -1 when its error is greater than 50m"

    But in reality, although this code works perfectly in DebugExpressions and piston, it only works on the beacon light when the target is < 300~400m from my plane. That's why I suspect it could be an overflow issue.

    Such situations are common when the code involves squares. square makes values much larger. I remember when I was trying to do the AFN2 navigation instrument, and it had similar problems too.

    4.2 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @vcharng
    .
    Beacons light up whenever input > 0. Is that what you want happening? Not some specific indication?

    4.2 years ago
  • Profile image
    9,445 vcharng

    @SnoWFLakE0s Yes I did. Is that a wrong thing to do?

    4.2 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @vcharng
    .
    Are you directly inserting this code into the input of beacon lights?

    4.2 years ago
  • Profile image
    9,445 vcharng

    @SnoWFLakE0s The code is:

    sign(2500 - (pow((Longitude + GS * sin(Heading) * (TargetDistance / (- rate(TargetDistance)))) - ((Longitude + TargetDistance * sin(TargetHeading)) + rate((Longitude + TargetDistance * sin(TargetHeading))) * (TargetDistance / (- rate(TargetDistance)))), 2) + pow((Latitude + GS * cos(Heading) * (TargetDistance / (- rate(TargetDistance)))) - ((Latitude + TargetDistance * cos(TargetHeading)) + rate((Latitude + TargetDistance * cos(TargetHeading))) * (TargetDistance / (- rate(TargetDistance)))), 2)))
    

    this exact same code works for piston and DebugExpression, but only works for beacon light when the target is < 400m away.

    4.2 years ago
  • Profile image
    67.1k SnoWFLakE0s

    @WereOutOfNamesArentWe
    .
    For some reason that didn't trigger a notification, but luckily I found the post regardless.
    .
    As for the question in the post, to my knowledge I don't think there is an issue with overflow, ever. SP is 32-bit, there's no way you're exceeding the 32bit cap. I don't know what's meant by using beacon lights without adequate context, but beacon lights function when the input > 0, as more clearly delineated in v1.10. Perhaps that's the issue? I've worked with large numbers before, it's never actually been an issue. Pasting source code can help me troubleshoot the exact source of the error.

    4.2 years ago
  • Profile image
    9,445 vcharng

    Just an extra note, the same formula worked for piston.
    So now I just use piston instead of signal light.

    4.2 years ago