From 9ffbaa542880114a67b9040321d1ba2e7e451e72 Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Wed, 8 Apr 2026 10:52:20 +0200 Subject: [PATCH] =?UTF-8?q?Fix=20D<,=20COMPARE,=20add=20-TRAILING=20?= =?UTF-8?q?=E2=80=94=20double=2027=E2=86=9216,=20string=2017=E2=86=9213?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - D< used D- D0< which overflows for extreme signed doubles. Replaced with high-cell comparison + unsigned low-cell comparison. - COMPARE had inverted sign for length difference (u2-u1 vs u1-u2). - Added -TRAILING (removed during Phase 6 refactoring, never re-added). --- crates/core/boot.fth | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/crates/core/boot.fth b/crates/core/boot.fth index 4614618..34a9f3f 100644 --- a/crates/core/boot.fth +++ b/crates/core/boot.fth @@ -98,7 +98,9 @@ : D= D- D0= ; \ D< ( d1 d2 -- flag ) true if d1 < d2 (signed) -: D< D- D0< ; +\ Cannot use D- D0< because subtraction overflows for extreme values. +\ Compare high cells first (signed); if equal, compare low cells unsigned. +: D< ROT 2DUP = IF 2DROP U< ELSE 2SWAP 2DROP > THEN ; \ D2* ( d -- d*2 ) double-cell shift left : D2* 2DUP D+ ; @@ -255,7 +257,7 @@ \ COMPARE ( addr1 u1 addr2 u2 -- n ) compare two strings lexicographically : COMPARE - ROT 2DUP - >R + ROT 2DUP SWAP - >R MIN 0 ?DO OVER I + C@ OVER I + C@ @@ -270,6 +272,9 @@ 0> IF 1 EXIT THEN 0 ; +\ -TRAILING ( c-addr u1 -- c-addr u2 ) remove trailing spaces +: -TRAILING BEGIN DUP WHILE 2DUP + 1- C@ BL = WHILE 1- REPEAT THEN ; + \ SEARCH stays as a host function (complex multi-line control flow). \ ---------------------------------------------------------------