Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 9, 2015 18:19:14 GMT 1
I've written simple program to calculate digits of Pi. It works with concat$, but doesn't with &.
This works:
global n = 14000 local f type int array n for x = 0 to n f[x] = 2000 next liczbapi$ = "" a = 10000 b = 0 for c = n to 14 step -14 d = 0 for b = c to 1 step -1 d = d * b g = b * 2 -1 d = d + f[b] * a f[b] = mod(d, g) d = floor(d / g) next liczbapi$ = concat$(liczbapi$, right$("000" & str$(e + floor(d / a)),4)) e = mod(d, a) next print liczbapi$
However, if you change 18th line to liczbapi$ = liczbapi$ & right$("000" & str$(e + floor(d / a)),4) you get a "segmentation fault" error or an empty liczbapi$ string.
|
|
|
Post by Pjot on May 9, 2015 19:57:44 GMT 1
Thanks Tomaaz,
In fact, there are two problems with your program.
(1) The "segmentation fault" is caused by the wrong usage of arrays. If you declare an array like 'local f type int array n' then such an array has a range from 0 to n-1. Therefore, your program must be adapted to the following:
global n = 14000 local f type int array n for x = 0 to n-1 f[x] = 2000 next liczbapi$ = "" a = 10000 b = 0 for c = n-1 to 14 step -14 d = 0 for b = c to 1 step -1 d = d * b g = b * 2 -1 d = d + f[b] * a f[b] = mod(d, g) d = floor(d / g) next liczbapi$ = liczbapi$ & right$("000" & str$(e + floor(d / a)),4) e = mod(d, a) next print liczbapi$
This will fix any seg faults.
(2) The other problem is in the '&' implementation. This is a bug at BaCon side in the last string optimization. The '&' operator counts the amount of string functions left and right from itself. However, when it starts counting the right side, the total amount was reset to '0'. The end result in your program was that the string function counter only saw one string function on line 21, while there should be 3.
I will upload a fixed version shortly.
Thanks again! Peter
|
|
|
Post by Pjot on May 9, 2015 20:16:41 GMT 1
Hi Tomaaz, All issues fixed in 3.0.4 beta. BR Peter
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 9, 2015 21:37:50 GMT 1
Yes, I suspected that the "segmentation fault" error may have been caused by something else, as it appeared after I rewrote the whole program from scratch. Thanx for replying and fixing the issue so quickly!
|
|
|
Post by vovchik on May 10, 2015 11:01:40 GMT 1
Dear Tomaaz and Peter, Thanks to both of you - Tomaaz for finding the bug and Peter for the extremely rapid fix. It's a great example of how Open Source should function. With kind regards, vovchik
|
|
Deleted
Deleted Member
Posts: 0
|
Post by Deleted on May 10, 2015 17:11:57 GMT 1
Dear Tomaaz and Peter, Thanks to both of you - Tomaaz for finding the bug and Peter for the extremely rapid fix. It's a great example of how Open Source should function. With kind regards, vovchik BaCon is the poster child of how open source projects should be run and managed. One could write a How-To Open Source book based on it's history.
|
|