08-20-2022, 03:49 AM
@Jack I spent a little time digging into the source for BTEN$ -- apparently this version doesn't actually calculate SQRT for us. Instead, it SQUARES a number for us. (x ^ 2)
I definitely remember there being a string routine which did square roots, but from what I remember of the layout of the code, it wasn't structured anything like this. What Dark had created for his square root calculator was a simple process that took 2 numbers and multiplied them together to aim for the target value and expanded one digit at a time.
For example to calculate the square root of 2, it'd first see what QB64 would give it as a seed.
Seed = SQR(2) ... which QB64 tells us is 1.414213562373095
Then it'd multiple that value by itself to see if it had a perfect match.
If not, it'd then multiple that value + "5" by itself. 1.4142135623730955 <-- see the added 5?
That value would then multiply by itself.
If the result was > the target, ir changed 5 to 2 and tried again. 1.4142135623730952 <-- 2 at the end
If the result was < the target, it changed 5 to 8 and tried again. 1.4142135623730958 <-- 8 at the end
And it basically continued this process until it narrowed the range to being between to digits. 2 is too small, 3 is too large -- the target value is 2!
And then it repeated that same multiplication process once again to get the next digit. 1.4142135623730952 + "5"
And that's how Dark's SQRT code worked, from what I remember of it, wherever the heck it went!
As for what's in the BTEN, you can use it via a simple call like so:
result$ = BTEN$(num$, "2", "") <-- and this will square the number for you.
Why he wrote a whole operator to handle such a thing, I don't know, and there's no way to ask him now that I know of. Seems to me that it'd be just as easy to do a simple: result$ = BTEN$(num$, "*", num$)
I'll dig around on the hard drives some later and see if I can find his actual SQRT calculator. I remember well how it works, but for whatever reason, it's not a part of the BTEN string routine which he shared and put into QB64 back in the day.
I definitely remember there being a string routine which did square roots, but from what I remember of the layout of the code, it wasn't structured anything like this. What Dark had created for his square root calculator was a simple process that took 2 numbers and multiplied them together to aim for the target value and expanded one digit at a time.
For example to calculate the square root of 2, it'd first see what QB64 would give it as a seed.
Seed = SQR(2) ... which QB64 tells us is 1.414213562373095
Then it'd multiple that value by itself to see if it had a perfect match.
If not, it'd then multiple that value + "5" by itself. 1.4142135623730955 <-- see the added 5?
That value would then multiply by itself.
If the result was > the target, ir changed 5 to 2 and tried again. 1.4142135623730952 <-- 2 at the end
If the result was < the target, it changed 5 to 8 and tried again. 1.4142135623730958 <-- 8 at the end
And it basically continued this process until it narrowed the range to being between to digits. 2 is too small, 3 is too large -- the target value is 2!
And then it repeated that same multiplication process once again to get the next digit. 1.4142135623730952 + "5"
And that's how Dark's SQRT code worked, from what I remember of it, wherever the heck it went!
As for what's in the BTEN, you can use it via a simple call like so:
result$ = BTEN$(num$, "2", "") <-- and this will square the number for you.
Why he wrote a whole operator to handle such a thing, I don't know, and there's no way to ask him now that I know of. Seems to me that it'd be just as easy to do a simple: result$ = BTEN$(num$, "*", num$)
I'll dig around on the hard drives some later and see if I can find his actual SQRT calculator. I remember well how it works, but for whatever reason, it's not a part of the BTEN string routine which he shared and put into QB64 back in the day.