A test program?
Re: A test program?
Chromatix wrote:
Quote:
Can you predict what this 5 liner is going to output without RUNning it? Better yet, can you explain why this works?
Bill
Re: A test program?
Thanks for the offerings Bruce - I've linked this thread over in the Stardot thread about type-ins for unattended Beebs.
Edit: ahem, thanks also to Mike and Bill for their offerings!
Edit: ahem, thanks also to Mike and Bill for their offerings!
Re: A test program?
BillO wrote:
With the precision of most small BASIC interpreters, looping 5 times seems optimistic. That algorithm should converge pretty quickly
An equivalent program in C using "long double" format on an Intel-based Mac converges after 3 iterations, with 10 decimals being correct after the second.
Re: A test program?
It would be amusing to change the loop from
20 FOR I=1 TO 5
to
20 FOR I=1 TO 3.14
20 FOR I=1 TO 5
to
20 FOR I=1 TO 3.14
Re: A test program?
BillO wrote:
With the precision of most small BASIC interpreters, looping 5 times seems optimistic. That algorithm should converge pretty quickly
The number of correct digits should roughly triple after each iteration. If the approximation P is pi+x where x (which can be positive or negative) is the error, then:
P + sin(P)
= pi+x + sin(pi+x)
= pi+x - sin(x), using the trig identity for sin(pi+x)
= pi+x - x + x^3 / 3! - x^5 / 5! + ..., using the power series for sin(x)
= pi + x^3 / 3! - x^5 / 5! + ...
and the new error is dominated by the x^3 term. If you have D correct digits, then x (the error) is about 10^-D (or for that matter base^-D since it doesn't have to be base 10); after the next iteration, the error is on the order of x^3 = (10^-D)^3 = 10^-(3*D), meaning roughly 3*D digits are now correct.
BigEd wrote:
20 FOR I=1 TO 3.14
Re: A test program?
Oh yes, EXP(1), I like that!
- floobydust
- Posts: 1394
- Joined: 05 Mar 2013
Re: A test program?
First, thanks to all who have offered some interesting test programs, much appreciated! I also found the WIDTH setting and changed the default, so the first test program (from Mike) works as it should along with the Mandelbrot program (from Bill). I've been swamped on other fronts this past week, but spent some time working on the code yesterday and late last night. and still trying to resolve some odd issues.
1- Using Ctrl-C will generally exit the running program, but attempting to RUN it again results in a BRK condition that the BIOS/Monitor routines traps. I have to Cold start EhBasic to resolve it.
2- Using a Warm start will show the existing program via LIST, but again, it won't RUN without a Cold start and re-entering the program.
There's more than the above... but I also tried the programs from Bruce with odd results. The first one's results:
The second's results:
The third program only printed blanks (spaces) on multiple lines, so not sure what it should be doing:
The fourth program runs endlessly (I eventually stop it) as:
So, still a ways to go.... I've had to re-arrange Page zero quite a bit and moved the CHRGET/CHRGOT routine from Page Zero to ROM... I'm not using EhBasic to intercept the IRQ/NMI routines yet either. I'm hoping to get more free time to work on this in the near future... but retirement has gotten overly busy, who knew 
1- Using Ctrl-C will generally exit the running program, but attempting to RUN it again results in a BRK condition that the BIOS/Monitor routines traps. I have to Cold start EhBasic to resolve it.
2- Using a Warm start will show the existing program via LIST, but again, it won't RUN without a Cold start and re-entering the program.
There's more than the above... but I also tried the programs from Bruce with odd results. The first one's results:
Code: Select all
Ready
10 P=3
20 FOR I=1 TO 5
30 PRINT P
40 P=P+SIN(P)
50 NEXT
RUN
3
3.14112
3.14159
3.14159
3.14159
ReadyCode: Select all
Ready
100 DIM N(104)
110 FOR T=1 TO 104:N(T)=2:NEXT
120 FOR D=1 TO 31
130 Q=0
140 FOR T=104 TO 1 STEP -1
150 B=2*T-1
160 IF T=1 THEN B=10
170 R=T*Q+N(T)*10:Q=INT(R/B):N(T)=R-Q*B
180 NEXT
190 PRINT Q;
200 IF D=1 THEN PRINT ".";
210 NEXT
RUN
3. 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9
ReadyCode: Select all
Ready
10 P=ATN(1)*4
20 FOR Y = -10.5 TO 10.5
30 FOR X = -10.75 TO 10.75 STEP .5
40 A=ATN(Y/X)+(X<0)*SGN(Y)*P
50 C=(SQR(X*X+Y*Y)-A/2)/P
60 PRINT CHR$(32+3*(C-INT(C)<.4));
70 NEXT
80 PRINT
90 NEXT
RUN
ReadyCode: Select all
Ready
10 W=79
20 DIM A(W+1):A(W/2+1)=1
30 FOR I=0 TO 7:B(I)=ASC(MID$("00011110",8-I))-48:NEXT
40 P=A(W):A(W+1)=A(1):FOR I=1 TO W:N=A(I)
50 PRINT CHR$(32+3*N);
60 A(I)=B(4*P+2*N+A(I+1)):P=N:NEXT:PRINT
70 GOTO 40
RUN
#
###
## #
## ####
## # #
## #### ###
## # # #
## #### ######
## # ### #
## #### ## # ###
## # # #### ## #
## #### ## # # ####
## # ### ## ## # #
## #### ## ### ### ## ###
## # # ### # ### # #
## #### ## # # ##### #######
## # ### #### # ### #
## #### ## ### ## ## # ###
## # # ### # ## ### #### ## #
## #### ## # ###### # # ### ####
## # ### #### #### ### ## # #
## #### ## ### # ## # # # ### ###
## # # ### # ### ## # ### ## # # # #
## #### ## # ### # # #### # # ## ######
## # ### #### ## ##### # ##### # # #
## #### ## ### # ## # # ## # ##### ###
## # # ### # ## # #### ## # ## ## # ## #
## #### ## # ### # # # ### #### # ## # ## # ####
## # ### #### #### ## ## ### # # #### # # #
## #### ## ### # ## # # ### # ## #### ### ## ###
## # # ### # ## # # ##### # ###### # # ## # # #
## #### ## # ### # # #### #### #### ## # # #########
## # ### #### #### # # ## # ## # # # # #
## #### ## ### # ## ## ### ## # ### ## # ##### # ## ###
## # # ### # ## # # ## # # # # # #### # # # ## #
## #### ## # ### # # #### #### ##### ## ##### # ## # ## ## ####
## # ### #### #### # # # # # # ### ## # # ### # #
## #### ## ### # ## ## ### ### ###### ## # # ### # # #### ###
## # # ### # ## # # ## ### ### # ## ### ## ## # # #### # #
## #### ## # ### # # #### # ### ### # # ## ### # ## ## # # ######
# ### #### #### # ###### ### # ## ## ### ###### # ## #####
### ## ### # ## ## ## ### # ## # # # ### ###### # #
## # ### # ## # # ## # # ## ### # ########## # ## #### ###
## # ## # ### # # #### ### ## ## ### #### #### ## # ## ### #
# # # #### #### # # # # # # ## # ## # ## ## # ## #####
### #### # ## ## ### ########### # # ### ## # ##### # # # ###
## # # ## # # ## ### # # # # # ## #### ###### # # #
# # ### ## # # #### # # ### ## # ##### ## ### # ## # ##### #
# # # #### # ###### # # ## # # # # # ##### # ## # #
### ## ##### ## ## ##### ## ### ## ######## # ## ## ## ##
# # # ## # # ## # ## # # # ## ## ## ### ### # ##
###### ##### ### ## ## # ### ## #### ## # # # ## # ## # # # # #
# ## ### # # ### #### # # # # # ## ## # # #### ### ## # #
# # ## # ### ## # ### # ###### ##### # # # ## ### # # # # # #
### ## ## #### ## # #### # ## # ### # # #### # # ## ### ##### #
# # # # # ##### ### # ## ## # ## # # #### ## # ### # #
# ######### ## # # # ## #### # ## #### ## # ## ## # # # # ### ##
### ### # ## ## # # ## # # # # ### # # # ##### #### # # ##
## # ## ### # ### # # # # ## ##### ## # #### #### # #### # #
#### ## ### # # ### # # #### # ### ## ## # # ### ## # #
### # ## # # ## #### # # # #### ## ### # # ### ### ## ### # ## #
# ##### ###### # # # ## # ## ## ### ### ### #### # # ### #### #
# ## # # ##### ## # # # # # ## # ### # # ### ## # # ## ###
# ## ### ## # #### #### # # # ##### # ### ## # # #### # # ##
##### # ## # ## # ##### # # # # # ### # # ## ##### # # # #
## # # ###### ## ## # ### ## # # ## ## ## ##### # # ## # # ##
# ## # # ### # # ##### ### # # # ### # ## # #### ##### # # #
### ## # ## ## ### #### ### ### # # # # # #### ## ### ### # ##
# # ### # # ## ### # # ## ### # # ## ## # # ### # ## # ## # #
### ## # # # # # # ### ##### ### # ## # # # # ## ## # # ###### # ## ##
# ## ## # ####### # # # ### # # ####### # # # ## # # # # #
##### # # # ## ### ##### #### # #### # # # ## ## #####
# ## ###### ## ## # # ## # ## ## ## # #### # # ## #
# # # ## # # ##
Break in line 40
ReadyRegards, KM
https://github.com/floobydust
https://github.com/floobydust
Re: A test program?
The third program will not work as written for EhBASIC.
Change:
60 PRINT CHR$(32+3*(C-INT(C)<.4));
to :
60 PRINT CHR$(32-3*(C-INT(C)<.4));
The issue is that in EhBASIC logical TRUE is -1, but in most Microsoft BASICs logical TRUE is 1.
Change:
60 PRINT CHR$(32+3*(C-INT(C)<.4));
to :
60 PRINT CHR$(32-3*(C-INT(C)<.4));
The issue is that in EhBASIC logical TRUE is -1, but in most Microsoft BASICs logical TRUE is 1.
Bill
Re: A test program?
Quote:
3. 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3 2 3 8 4 6 2 6 4 3 3 8 3 2 7 9
Also note that all variables involved (including the array) take on only integer values, so if trying this in a version of BASIC that recognises the difference, declaring them as integer variables results in a big speedup with no difference in output. In BBC BASIC that means appending % to each variable name, and using "R% DIV B%" instead of "INT(R%/B%)".
Quote:
The issue is that in EhBASIC logical TRUE is -1, but in most Microsoft BASICs logical TRUE is 1.
-
JenniferDigital
- Posts: 92
- Joined: 25 May 2015
Re: A test program?
Don't forget to use WIDTH 80,<whatever width you want between commas>
Re: A test program?
Chromatix wrote:
Quote:
The issue is that in EhBASIC logical TRUE is -1, but in most Microsoft BASICs logical TRUE is 1.
Bill
- barrym95838
- Posts: 2056
- Joined: 30 Jun 2013
- Location: Sacramento, CA, USA
Re: A test program?
The 1 for true thing seemed to be an Applesoft deal, because MS-BASIC on the TRS-80 and C=64 used -1. Other languages that used 1 for true, off the top of my head: K&R C, VTL-2, Fig-Forth.
Mike B.
Mike B.
Re: A test program?
barrym95838 wrote:
The 1 for true thing seemed to be an Applesoft deal, because MS-BASIC on the TRS-80 and C=64 used -1. Other languages that used 1 for true, off the top of my head: K&R C, VTL-2, Fig-Forth.
Mike B.
Mike B.
It does indeed seem to flip around from implementation to implementation in other languages too. I was always taught to test for FALSE=0 or TRUE <> 0 as it is the only fairly consistent arithmetic value assigned to a LOGICAL value.
Bill
Re: A test program?
TRUE = -1 seems to be the better choice because you can use a logical NOT (one´s complement) to invert it to FALSE.
6502 sources on GitHub: https://github.com/Klaus2m5
Re: A test program?
Indeed. In C there are separate Boolean and bitwise inversion operators, just as there are separate Boolean and bitwise AND and OR operators. BASIC only has bitwise ones, which thus have to pull double duty.