Sujet : Re: May the numbers speak
De : dxforth (at) *nospam* gmail.com (dxf)
Groupes : comp.lang.forthDate : 11. Jun 2025, 19:00:56
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <73357bfe46cea40d8c795ee213cf77c0a0a53d86@i2pn2.org>
References : 1
User-Agent : Mozilla Thunderbird
On 11/06/2025 11:54 pm, LIT wrote:
Let's find out the difference between my
and "Mark Twain" 's approach to the solution
of "parsing 'time string' task". For simplicity
I'll do everything using DX Forth.
My solution is:
VARIABLE C6
VARIABLE C1
: TIMESTRSCAN ( addr count -- d )
1 C6 ! 1 C1 !
>R >R 0 0 R> R>
OVER + 1-
DO
I C@ DUP 58 =
IF
DROP
C6 @ 60 * C6 !
1 C1 !
ELSE
48 - C1 @ * C6 @ M* D+
10 C1 !
THEN
-1 +LOOP
;
Same using stack ops:
: TIMESTRSCAN2 ( addr count -- d )
>R >R 0 0 1 1 ( C6 C1) R> R>
OVER + 1- DO
I C@ DUP 58 = IF DROP
DROP 60 * ( C6) 1 ( C1)
ELSE
48 - * OVER ( C6) >R UM* D+ R> 10 ( C1)
THEN
-1 +LOOP 2DROP ;
12% faster and 20% smaller by my measurement.