Infinity Trapping
BlitzPlus Forums/BlitzPlus Programming/Infinity Trapping
| ||
I've got something of a huge dilemma on my hands. My current project B+ crashes when attempting to mult two floats where the result is + infinity (overflows). It's taken a good day to locate the fault. The annoying thing is that if i clamp the multiplied values then it's safe, but this presents the problem of predicting possible over/underflows quickly. Not an ideal solution really.. What's more annoying is that if I isolate and test routine it works fine, it only seems to be issue when I need to do it in a much larger source .. . BEfore you ask, Yep, I'm trying to re-create the problem though. There's got to be something to triggers the error.. It's pretty limiting otherwise Has anybody else experienced this issue before?, any ideas on 'quick' way to predict an under/overflow ? |
| ||
The typical situation is that you divide a number by 0.0 or a really really small value, like: 0.000000001 |
| ||
There's no quicker way to test for overflow than to actually do the calculation. You then test the result to see if it went bad. Const PosInf# = 2^128 ; already overflowed Const NegInf# = -PosInf Once you have defined these constants you can compare numbers with them: If result# = PosInf# Then ... The problem gets worse if you continue using infinite results. This can lead to values that are NaN, which means Not a Number. For example, Sin(PosInf#) is NaN. You can test for NaN with this strange looking code: If result# > result# Then ... ; result is NaN |
| ||
Thanks that's actually quiet helpful. The bad news is that it dies during the multiply, or after closer inspection today, at virtually any math operation once a previous calculation hits infinity. The app throws an exception (invalid float point operation) and dies out. It seems to be more a result of a compilation error building the sources (which is the result of most of this years work, so it's rather long) as if I place the follow snippet for example at the start/middle/end of my program and jmp to it rather than running any of my app, it does it the same thing, throws an exception and quits. But if i compile this on it's own, and run the exe it's happy enough to print out infinity without dying. .Test_Infinity: TestingFloatA#=1234 For lp =0 To 300 TestingFloatA#=TestingFloatA#*TestingFloatA# Print TestingFloatA# Next ; Wait for INput before closing console z$=Input() End Does anybody know what physical limitations the B+ compiler has?, number variables/constants/arrays etc. I was messing around before and just creating a source with a 2300 variables, with the follow test, and it seems B+ refuses to compile it here. Doesn't seem to matter if their int or floats.. h=WriteFile("C:\Build_Massive_Test_SRC.bb") For lp=0 To 2300 v1$="a"+Str$(lp)+"#" s$=v1$+"="+1 WriteLine h,s$ Next CloseFile h Print "DONE" Input |
| ||
Sorry to be pushy, So nobody else has suffered this issue before ? |
| ||
There is a limit on local variables but not on globals. Here is a lengthy thread on this topic. |
| ||
Has anyone ever tried doing something like For i=1 to #Infinity ? =] </mostly offtopic> |
| ||
Floyd: Thanks again, that was helpful. Sadly, after moving the bulk, if not all the token variables to globals (their init'd dynamically, hence their not constants), it still seems to be crashing. Oh well, Will have to do some more reseach i think :( |