| 1 : |
anton
|
1.1
|
\ High level floating point 14jan94py |
| 2 : |
|
|
|
| 3 : |
|
|
: f, ( f -- ) here 1 floats allot f! ; |
| 4 : |
|
|
|
| 5 : |
anton
|
1.2
|
\ !! have create produce faligned pfas |
| 6 : |
anton
|
1.1
|
: fconstant ( r -- ) |
| 7 : |
pazsan
|
1.4
|
falign here f, Create A, |
| 8 : |
|
|
DOES> @ f@ ; |
| 9 : |
anton
|
1.1
|
|
| 10 : |
|
|
: fvariable |
| 11 : |
pazsan
|
1.4
|
falign here 0. d>f f, AConstant ; |
| 12 : |
anton
|
1.1
|
|
| 13 : |
|
|
: fdepth ( -- n ) f0 @ fp@ - [ 1 floats ] Literal / ; |
| 14 : |
|
|
|
| 15 : |
|
|
: FLit ( -- r ) r> faligned dup f@ float+ >r ; |
| 16 : |
|
|
: FLiteral ( r -- ) postpone FLit falign f, ; immediate |
| 17 : |
|
|
|
| 18 : |
|
|
&16 Value precision |
| 19 : |
|
|
: set-precision to precision ; |
| 20 : |
|
|
|
| 21 : |
|
|
: scratch ( r -- addr len ) |
| 22 : |
|
|
pad precision - precision ; |
| 23 : |
|
|
|
| 24 : |
|
|
: zeros ( n -- ) 0 max 0 ?DO '0 emit LOOP ; |
| 25 : |
|
|
|
| 26 : |
|
|
: -zeros ( addr u -- addr' u' ) |
| 27 : |
|
|
BEGIN dup WHILE 1- 2dup + c@ '0 <> UNTIL 1+ THEN ; |
| 28 : |
|
|
|
| 29 : |
pazsan
|
1.4
|
: f$ ( f -- n ) scratch represent 0= |
| 30 : |
|
|
IF 2drop scratch 3 min type rdrop EXIT THEN |
| 31 : |
|
|
IF '- emit THEN ; |
| 32 : |
|
|
|
| 33 : |
|
|
: f. ( r -- ) f$ dup >r 0< |
| 34 : |
|
|
IF '0 emit |
| 35 : |
anton
|
1.1
|
ELSE scratch r@ min type r@ precision - zeros THEN |
| 36 : |
|
|
'. emit r@ negate zeros |
| 37 : |
|
|
scratch r> 0 max /string 0 max -zeros type space ; |
| 38 : |
benschop
|
1.3
|
\ I'm afraid this does not really implement ansi semantics wrt precision. |
| 39 : |
|
|
\ Shouldn't precision indicate the number of places shown after the point? |
| 40 : |
anton
|
1.1
|
|
| 41 : |
pazsan
|
1.4
|
: fe. ( r -- ) f$ 1- s>d 3 fm/mod 3 * >r 1+ >r |
| 42 : |
anton
|
1.1
|
scratch r@ min type '. emit scratch r> /string type |
| 43 : |
|
|
'E emit r> . ; |
| 44 : |
|
|
|
| 45 : |
pazsan
|
1.4
|
: fs. ( r -- ) f$ 1- |
| 46 : |
|
|
scratch over c@ emit '. emit 1 /string type |
| 47 : |
|
|
'E emit . ; |
| 48 : |
|
|
|
| 49 : |
|
|
: fnumber ( string -- r / ) |
| 50 : |
|
|
?dup IF dup count >float 0= |
| 51 : |
|
|
IF defers notfound |
| 52 : |
|
|
ELSE drop state @ |
| 53 : |
|
|
IF postpone FLiteral THEN THEN THEN ; |
| 54 : |
anton
|
1.1
|
|
| 55 : |
|
|
' fnumber IS notfound |
| 56 : |
|
|
|
| 57 : |
|
|
1e0 fasin 2e0 f* fconstant pi |