version 1.2, 2007/08/21 09:22:28
|
version 1.8, 2007/11/03 08:20:32
|
Line 7
|
Line 7
|
\ VERSION 1.1 |
\ VERSION 1.1 |
|
|
\ for the FNEARLY= stuff: |
\ for the FNEARLY= stuff: |
\ from ftester.fs written by David N. Williams, based on the |
\ from ftester.fs written by David N. Williams, based on the idea of |
\ approximate equality in Dirk Zoller's float.4th |
\ approximate equality in Dirk Zoller's float.4th |
|
\ public domain |
\ This library is free software; you can redistribute it and/or |
|
\ modify it under the terms of the GNU Lesser General Public |
|
\ License as published by the Free Software Foundation; either |
|
\ version 2.1 of the License, or at your option any later version. |
|
|
|
\ This library is distributed in the hope that it will be useful, |
|
\ but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
\ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
|
\ Lesser General Public License for more details. |
|
|
|
\ You should have received a copy of the GNU Lesser General Public |
|
\ License along with this library; if not, write to the Free |
|
\ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
|
\ MA 02111-1307 USA. |
|
|
|
\ for the rest: |
\ for the rest: |
\ revised by Anton Ertl 2007-08-12, 2007-08-19 |
\ revised by Anton Ertl 2007-08-12, 2007-08-19, 2007-08-28 |
\ public domain |
\ public domain |
|
|
\ The original has the following shortcomings: |
\ The original has the following shortcomings: |
Line 44
|
Line 30
|
\ http://www.forth200x.org/tests/ttester.fs |
\ http://www.forth200x.org/tests/ttester.fs |
|
|
\ tester.fs is intended to be a drop-in replacement of the original. |
\ tester.fs is intended to be a drop-in replacement of the original. |
\ ttester.fs is a version that uses T{ and }T instead of { and }. |
|
|
\ ttester.fs is a version that uses T{ and }T instead of { and } and |
|
\ keeps the BASE as it was before loading ttester.fs |
|
|
\ In spirit of the original, I have strived to avoid any potential |
\ In spirit of the original, I have strived to avoid any potential |
\ non-portabilities and stayed as much within the CORE words as |
\ non-portabilities and stayed as much within the CORE words as |
Line 53
|
Line 41
|
|
|
\ There are a few things to be noted: |
\ There are a few things to be noted: |
|
|
\ - Following the despicable practice of the original, this version |
\ - Loading ttester.fs does not change BASE. Loading tester.fs |
\ sets the base to HEX for everything that gets loaded later. |
\ changes BASE to HEX (like the original tester). Floating-point |
\ Floating-point input is ambiguous when the base is not decimal, so |
\ input is ambiguous when the base is not decimal, so you have to set |
\ you have to set it to decimal yourself when you want to deal with |
\ it to decimal yourself when you want to deal with decimal numbers. |
\ decimal numbers. |
|
|
|
\ - For FP it is often useful to use approximate equality for checking |
\ - For FP it is often useful to use approximate equality for checking |
\ the results. You can turn on approximate matching with SET-NEAR |
\ the results. You can turn on approximate matching with SET-NEAR |
Line 72
|
Line 59
|
\ system or if you need only exact matching, you can use the plain }T |
\ system or if you need only exact matching, you can use the plain }T |
\ instead. |
\ instead. |
|
|
|
BASE @ |
HEX |
HEX |
|
|
\ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY |
\ SET THE FOLLOWING FLAG TO TRUE FOR MORE VERBOSE OUTPUT; THIS MAY |
Line 112 HAS-FLOATING [IF]
|
Line 100 HAS-FLOATING [IF]
|
\ SET THE FOLLOWING TO THE RELATIVE AND ABSOLUTE TOLERANCES YOU |
\ SET THE FOLLOWING TO THE RELATIVE AND ABSOLUTE TOLERANCES YOU |
\ WANT FOR APPROXIMATE FLOAT EQUALITY, TO BE USED WITH F~ IN |
\ WANT FOR APPROXIMATE FLOAT EQUALITY, TO BE USED WITH F~ IN |
\ FNEARLY=. KEEP THE SIGNS, BECAUSE F~ NEEDS THEM. |
\ FNEARLY=. KEEP THE SIGNS, BECAUSE F~ NEEDS THEM. |
FVARIABLE FSENSITIVITY DECIMAL 1E-12 HEX FSENSITIVITY F! |
FVARIABLE REL-NEAR DECIMAL 1E-12 HEX REL-NEAR F! |
: REL-NEAR FSENSITIVITY ; |
|
FVARIABLE ABS-NEAR DECIMAL 0E HEX ABS-NEAR F! |
FVARIABLE ABS-NEAR DECIMAL 0E HEX ABS-NEAR F! |
|
|
\ WHEN EXACT? IS TRUE, }F USES FEXACTLY=, OTHERWISE FNEARLY=. |
\ WHEN EXACT? IS TRUE, }F USES FEXACTLY=, OTHERWISE FNEARLY=. |
Line 187 HAS-FLOATING-STACK [IF]
|
Line 174 HAS-FLOATING-STACK [IF]
|
: F-> ( ... -- ... ) |
: F-> ( ... -- ... ) |
FDEPTH DUP ACTUAL-FDEPTH ! |
FDEPTH DUP ACTUAL-FDEPTH ! |
START-FDEPTH @ > IF |
START-FDEPTH @ > IF |
FDEPTH START-FDEPTH @ DO ACTUAL-FRESULTS I FLOATS + F! LOOP |
FDEPTH START-FDEPTH @ - 0 DO ACTUAL-FRESULTS I FLOATS + F! LOOP |
THEN ; |
THEN ; |
|
|
: F} ( ... -- ... ) |
: F} ( ... -- ... ) |
Line 204 HAS-FLOATING-STACK [IF]
|
Line 191 HAS-FLOATING-STACK [IF]
|
THEN ; |
THEN ; |
|
|
: F...}T ( -- ) |
: F...}T ( -- ) |
FDEPTH START-FDEPTH @ = 0= IF |
FCURSOR @ START-FDEPTH @ + ACTUAL-FDEPTH @ <> IF |
S" WRONG NUMBER OF FP RESULTS" ERROR |
S" NUMBER OF FLOAT RESULTS BEFORE '->' DOES NOT MATCH ...}T SPRECIFICATION: " ERROR |
THEN |
ELSE FDEPTH START-FDEPTH @ = 0= IF |
FCURSOR @ ACTUAL-FDEPTH @ <> IF |
S" NUMBER OF FLOAT RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR |
S" WRONG NUMBER OF FP RESULTS" ERROR |
THEN THEN ; |
THEN ; |
|
|
|
: FTESTER ( R -- ) |
: FTESTER ( R -- ) |
FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ 1+ < OR IF |
FDEPTH 0= ACTUAL-FDEPTH @ FCURSOR @ START-FDEPTH @ + 1+ < OR IF |
S" WRONG NUMBER OF FP RESULTS: " ERROR EXIT |
S" NUMBER OF FLOAT RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR |
THEN |
ELSE ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF |
ACTUAL-FRESULTS FCURSOR @ FLOATS + F@ FCONF= 0= IF |
S" INCORRECT FP RESULT: " ERROR |
S" INCORRECT FP RESULT: " ERROR |
THEN THEN |
THEN |
|
1 FCURSOR +! ; |
1 FCURSOR +! ; |
|
|
[ELSE] |
[ELSE] |
Line 227 HAS-FLOATING-STACK [IF]
|
Line 213 HAS-FLOATING-STACK [IF]
|
: F} ; |
: F} ; |
: F...}T ; |
: F...}T ; |
|
|
|
DECIMAL |
: COMPUTE-CELLS-PER-FP ( -- U ) |
: COMPUTE-CELLS-PER-FP ( -- U ) |
DEPTH 0E DEPTH >R FDROP R> SWAP - ; |
DEPTH 0E DEPTH 1- >R FDROP R> SWAP - ; |
|
HEX |
|
|
COMPUTE-CELLS-PER-FP CONSTANT CELLS-PER-FP |
COMPUTE-CELLS-PER-FP CONSTANT CELLS-PER-FP |
|
|
: FTESTER ( R -- ) |
: FTESTER ( R -- ) |
DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ CELLS-PER-FP + < OR IF |
DEPTH CELLS-PER-FP < ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + CELLS-PER-FP + < OR IF |
S" WRONG NUMBER OF RESULTS: " ERROR EXIT |
S" NUMBER OF RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT |
THEN |
THEN |
ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF |
ACTUAL-RESULTS XCURSOR @ CELLS + F@ FCONF= 0= IF |
S" INCORRECT FP RESULT: " ERROR |
S" INCORRECT FP RESULT: " ERROR |
Line 260 HAS-FLOATING-STACK [IF]
|
Line 248 HAS-FLOATING-STACK [IF]
|
' ERROR1 ERROR-XT ! |
' ERROR1 ERROR-XT ! |
|
|
: T{ \ ( -- ) SYNTACTIC SUGAR. |
: T{ \ ( -- ) SYNTACTIC SUGAR. |
DEPTH START-DEPTH ! F{ ; |
DEPTH START-DEPTH ! 0 XCURSOR ! F{ ; |
|
|
: -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK. |
: -> \ ( ... -- ) RECORD DEPTH AND CONTENT OF STACK. |
DEPTH DUP ACTUAL-DEPTH ! \ RECORD DEPTH |
DEPTH DUP ACTUAL-DEPTH ! \ RECORD DEPTH |
START-DEPTH @ > IF \ IF THERE IS SOMETHING ON STACK |
START-DEPTH @ > IF \ IF THERE IS SOMETHING ON STACK |
DEPTH START-DEPTH @ DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM |
DEPTH START-DEPTH @ - 0 DO ACTUAL-RESULTS I CELLS + ! LOOP \ SAVE THEM |
THEN |
THEN |
F-> ; |
F-> ; |
|
|
Line 284 HAS-FLOATING-STACK [IF]
|
Line 272 HAS-FLOATING-STACK [IF]
|
F} ; |
F} ; |
|
|
: ...}T ( -- ) |
: ...}T ( -- ) |
DEPTH START-DEPTH @ = 0= IF |
XCURSOR @ START-DEPTH @ + ACTUAL-DEPTH @ <> IF |
S" WRONG NUMBER OF RESULTS" ERROR |
S" NUMBER OF CELL RESULTS BEFORE '->' DOES NOT MATCH ...}T SPECIFICATION: " ERROR |
THEN |
ELSE DEPTH START-DEPTH @ = 0= IF |
XCURSOR @ ACTUAL-DEPTH @ <> IF |
S" NUMBER OF CELL RESULTS BEFORE AND AFTER '->' DOES NOT MATCH: " ERROR |
S" WRONG NUMBER OF RESULTS" ERROR |
THEN THEN |
THEN |
|
F...}T ; |
F...}T ; |
|
|
: XTESTER ( X -- ) |
: XTESTER ( X -- ) |
DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ 1+ < OR IF |
DEPTH 0= ACTUAL-DEPTH @ XCURSOR @ START-DEPTH @ + 1+ < OR IF |
S" WRONG NUMBER OF RESULTS: " ERROR EXIT |
S" NUMBER OF CELL RESULTS AFTER '->' BELOW ...}T SPECIFICATION: " ERROR EXIT |
THEN |
ELSE ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF |
ACTUAL-RESULTS XCURSOR @ CELLS + @ <> IF |
S" INCORRECT CELL RESULT: " ERROR |
S" INCORRECT CELL RESULT: " ERROR |
THEN THEN |
THEN |
|
1 XCURSOR +! ; |
1 XCURSOR +! ; |
|
|
: X}T XTESTER ...}T ; |
: X}T XTESTER ...}T ; |
Line 337 HAS-FLOATING-STACK [IF]
|
Line 323 HAS-FLOATING-STACK [IF]
|
IF DUP >R TYPE CR R> >IN ! |
IF DUP >R TYPE CR R> >IN ! |
ELSE >IN ! DROP |
ELSE >IN ! DROP |
THEN ; |
THEN ; |
|
|
|
BASE ! |