Hi primo,
Disclaimer: I have not run your code, I have only looked through it. Still my comments can lead you in the proper direction for you to be able to understand and debug your code yourself.
In fact, PowerBASIC and thinBasic pass their function arguments differently on default: by reference and by copy, respectively. This means that before passing the arguments into the function, TB would make copies of them thus isolating whatever changes the function might make to their values, from the main code that called the function. OTOH PB would pass the arguments by reference so that every change made to the argument values is immediately propagated back to the caller code.
Your calcleng function modifies the original x, y, z arguments heavily but the mods can't affect the TB caller code because the arguments aren't in fact stored in the exact memory locations where they reside in the caller code. However the same function used in PB will propagate the mods back to the caller code and will thus spoil the calculation results for the subsequent iterations. At the same time, calcleng2 seen in the PB code uses local temp vars as buffers that isolate the mods from the function's original arguments passed by the caller code. That's why that function would perform identically to the TB calcleng function, while the PB calcleng function would fail.
Make it a habit to use explicit ByRef and ByVal parameter qualifiers to declare your function parameters in the both languages if you want to avoid similar pitfalls in the future.
Bookmarks