I have tried to make the equivalent of C's ternary operator in ZX81 BASIC.
B-(B-A AND L) was the most effective replacement I could find for L?A:B in C. Could it be improved?
http://www.df.lth.se.orbin.se/~mikaelb/ ... /ternary.p
Ternary operator in ZX81 BASIC
Ternary operator in ZX81 BASIC
Last edited by MOB-i-L on Sat Oct 26, 2013 9:53 am, edited 1 time in total.
Started w/ BASIC on ABC80 & ZX81 then Forth, Z80… http://scratch.mit.edu/users/mobluse/ https://www.youtube.com/user/MOBiL4u/ https://twitter.com/mobluse/
Re: Ternary operator in ZX81 BASIC
what about...
(A and L) + (B and not L)
Could do with running some speed tests, in the ZX81 shorter is not always quicker where math is concerned.... a single adding + 2 boolean i think is very slightly quicker then 2 subs and a single boolean.
Regards Andy
(A and L) + (B and not L)
Could do with running some speed tests, in the ZX81 shorter is not always quicker where math is concerned.... a single adding + 2 boolean i think is very slightly quicker then 2 subs and a single boolean.
Regards Andy
what's that Smell.... smells like fresh flux and solder fumes...
Re: Ternary operator in ZX81 BASIC
I did some tests with eo 50Hz slow mode.
100 loops with your
took 4,08 seconds when L=0 and 4,24 seconds when L=1
fastest I found was
took 3,36 seconds when L=0 and 3,94 seconds when L=1
all other examples were even slower.
Any better idea?
Paul
100 loops with your
Code: Select all
30 LET C=B-(B-A AND L)
fastest I found was
Code: Select all
30 LET C=B
40 IF L THEN LET C=A
all other examples were even slower.
Any better idea?
Paul
In theory, there is no difference between theory and practice. But, in practice, there is.
Re: Ternary operator in ZX81 BASIC
Good point, the expression evaluation involves the internal stack based FP calculator which is compact and powerful but damn slow.
i.e. compare the time it takes printing a constant (like PRINT 1) and a text string (as PRINT "1").
Your suggestion permits little more optimizations, in example, your speed test loop could be changed like this:
i.e. compare the time it takes printing a constant (like PRINT 1) and a text string (as PRINT "1").
Your suggestion permits little more optimizations, in example, your speed test loop could be changed like this:
Code: Select all
30 LET C=B
40 IF L THEN NEXT---
50 LET C=A
60 NEXT --