Dismal Arithmetic & 3 Progs for 49G & Others
05-11-2015, 04:16 PM
Post: #21
 Dave Britten Senior Member Posts: 1,961 Joined: Dec 2013
RE: Dismal Arithmetic & 2 Progs for 49G, the Prime, 48S & 32S & TI & C...
Now for something in BASIC: the Casio fx-702p "programmable calculator" (really more of a pocket computer). This is the slowest one yet, at 1:44 to do 435,821 * 2,949,229, but it DOES yield the full-precision result, 244,585,835,821, unlike the Casio graphing calculator. It displays 2.445858358E11, but you can pry the other digits out by executing F-2.445E11.

Just run it, tell it if you want to "A"dd, or "M"ultiply, then enter your two inputs.

Code:
1 INP "(A)DD (M)ULT:",$2$=MID(1,1) 10 IF $="A":INP "X",A,"Y",B:GSB 300:PRT S 20 IF$="M";INP "X",X,"Y",Y:GSB 400:PRT F 30 END 100 IF N=0;L=0:RET 110 L=INT LOG N+1:RET 200 R=FRAC (INT (N/10^(D-1))/10)*10:RET 300 N=A:GSB 100:C=L 310 N=B:GSB 100:IF L>C;C=L 320 S=0 330 FOR I=1 TO C 340 N=A:D=I:GSB 200:T=R 350 N=B:GSB 200:IF R>T;T=R 360 S=S+T*10^(I-1) 370 NEXT I 380 RET 400 N=X:GSB 100:Z=L 410 N=Y:GSB 100:J=L 420 F=0 430 FOR J=J TO 1 STEP -1 440 N=Y:D=J:GSB 200:M=R 450 P=0 460 FOR K=1 TO Z 470 U=M 480 N=X:D=K:GSB 200 490 IF R<U;U=R 500 P=P+U*10^(K-1) 510 NEXT K 520 A=P:B=10*F:GSB 300:F=S 530 NEXT J 540 PRT F Routines 1 Interactive Menu 100 Number Length 200 Get Digit 300 Add 400 Multiply Variables N - Number Length input L - Number Length result N - Get Digit input D - Get Digit digit number R - Get Digit result A - Addend 1 B - Addend 2 C - Add loop limit (addend max length) I - Add loop counter S - Sum T - Addition scratch register X - Factor 1 Y - Factor 2 Z - Factor 1 length J - Factor 2 length/outer loop counter K - Inner loop counter (factor 1) P - Product F - Sum of products M - Factor 2 current digit U - Multiply scratch register (digit comparison)

Notes: I think this is one of Casio's first BASIC machines, so it's got a few odd limitations.

A number of keywords are abbreviated from what's typically used (PRT, INP, GSB, RET, etc).

Variable naming and availability are limited much like the Sharp pocket computers. Single-character names, and some basic array functionality. Variables can hold numbers or strings (e.g. A vs. A$), but are limited to 7-character strings. The dedicated string variable, named simply$, can hold 30 characters.

There are two forms of the IF statement. This will do a GOTO if true:
IF X>3 THEN 90
And this will skip the rest of the line if false:
IF X>3;F=7:GSB 300
Note that you have to terminate the IF with a semicolon, whereas you use a colon to separate the rest of the statements.

The IF statement can't evaluate any compound expressions; there's no AND or OR functions! But you can string conditions together into a simple AND chain like this:
IF X>3;IF J<10;GSB 500:RET
Anything more complicated, and you're going to be doing GOTO stunts.

There's no DATA or READ statements. Not an issue here, but it was an annoying discovery when I was porting the usual prime factors program.

It's sloooow. It took almost 5 times as long as running the same algorithm on the Casio fx-8500g.

Despite all that, I like it, largely because it has slots for 10 independent programs, like most Casios do. The Sharp and TI offerings typically only provide a single program space.
 « Next Oldest | Next Newest »

 Messages In This Thread Dismal Arithmetic & 3 Progs for 49G & Others - Gerald H - 04-21-2015, 04:18 PM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Didier Lachieze - 04-21-2015, 09:19 PM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Gerald H - 04-22-2015, 07:04 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Didier Lachieze - 04-22-2015, 07:16 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Didier Lachieze - 04-22-2015, 07:45 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Dave Britten - 04-22-2015, 01:09 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - brouhaha - 04-22-2015, 01:18 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Tugdual - 04-22-2015, 06:55 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Gerald H - 04-22-2015, 08:54 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Didier Lachieze - 04-22-2015, 09:56 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G - Gerald H - 04-22-2015, 10:07 AM RE: Dismal Arithmetic with Two Programmes for the HP 49G & the Prime - Dave Britten - 05-06-2015, 05:34 PM RE: Dismal Arithmetic with Two Programmes for the HP 49G & the Prime & the HP 48S - Dave Britten - 05-07-2015, 01:48 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Gerald H - 05-07-2015, 03:25 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Gerald H - 05-07-2015, 03:57 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Gerald H - 05-07-2015, 04:59 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Dave Britten - 05-07-2015, 05:36 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Gerald H - 05-07-2015, 06:01 PM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Dave Britten - 05-08-2015, 01:35 AM RE: Dismal Arithmetic with Two Programmes 49G, the Prime, 48S & 32S - Dave Britten - 05-08-2015, 02:53 PM RE: Dismal Arithmetic & 2 Progs for 49G, the Prime, 48S & 32S & TI & C... - Dave Britten - 05-11-2015 04:16 PM RE: Dismal Arithmetic & 2 Progs for 49G, the Prime, 48S & 32S & TI & C... - Marcus von Cube - 05-11-2015, 06:04 PM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Gerald H - 05-13-2015, 09:19 AM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Dave Britten - 05-13-2015, 05:59 PM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Gerald H - 05-13-2015, 06:37 PM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Dave Britten - 05-13-2015, 07:26 PM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Gerald H - 10-28-2015, 02:17 PM RE: Dismal Arithmetic & 3 Progs for 49G & Others - Gerald H - 10-30-2015, 10:43 AM

User(s) browsing this thread: 1 Guest(s)