home *** CD-ROM | disk | FTP | other *** search
- ( -------------------------------------------------------- )
- ( MATH.FTH )
- ( Copyright (C) 1992 K. Peper & DMV-Verlag )
- ( Compiler: Naxos V 1.0 )
- ( -------------------------------------------------------- ) )
-
-
- include kern
-
- typ bcd byte 10 ;
- typ real byte 8 ;
-
- VAR DPLP byte ;
- VAR SCALE real ;
- VAR FHLD word ;
- var LDZ byte ;
-
- : F@
- [ $DD $07 ] ( FLD [bx] )
- ;
-
-
- : FI@
- [ $DF $07 ] ( FILD w/[bx] )
- ;
-
- : FD@
- [ $DB $07 ] ( FILD d/[bx] )
- ;
-
- : FBCD@
- [ $DF $27 ] ( FBLD [bx] )
- ;
-
- : F!
- [ $9B $DD $1F ] ( FSTP [bx] )
- ;
-
- : FI!
- [ $9B $DF $1F ] ( FISTP w/[bx] )
- ;
-
- : FD!
- [ $9B $DB $1F ] ( FISTP d/[bx] )
- ;
-
- : FBCD!
- [ $9B $DF $37 ] ( FBSTP [bx] )
- ;
-
- : F> ( ST --> ax )
- bcd FI! bcd @
- ;
-
- : >F ( ax --> ST )
- bcd ! bcd FI@
- ;
-
- : F>D ( ST --> dx:ax )
- bcd FD! bcd D@
- ;
-
- : D>F ( dx:ax --> ST )
- bcd D! bcd FD@
- ;
-
- : FIPUSH ( ST --> sx )
- [ $4E $4E ] ( dec si dec si )
- [ $DF $1C ] ( FISTP w/[si] )
- ;
-
- : FIPOP ( sx --> ST )
- [ $DF $04 ] ( FILD w/[si] )
- [ $46 $46 ] ( inc si inc si )
- ;
-
- : FDPUSH ( ST --> sx )
- [ $4E $4E $4E $4E ] ( 4* dec si )
- [ $DB $1C ] ( FISTP d/[si] )
- ;
-
- : FDPOP ( sx --> ST )
- [ $DB $04 ] ( FILD d/[si] )
- [ $46 $46 $46 $46 ] ( 4* inc si )
- ;
- : F+ ( ST+ST(1) --> ST )
- [ $DE $C1 ] ( FADDP ST(1),ST )
- ;
-
- : F- ( st(1)-st --> st )
- [ $DE $E9 ] ( FSUBP ST(1),ST )
- ;
-
- : F* ( st(1)*st --> st )
- [ $DE $C9 ] ( FMULP ST(1),ST )
- ;
-
- : F/ ( st(1)/st --> st )
- [ $DE $F9 ] ( FDIVP ST(1),ST )
- ;
-
- : FABS ( ABS(ST) --> ST )
- [ $D9 $E1 ] ( FABS )
- ;
-
- : FMINUS ( ST* -1 --> ST )
- [ $D9 $E0 ] ( FCHS )
- ;
-
- : FSWAP ( ST <--> ST(1) )
- [ $D9 $C9 ] ( FXCH )
- ;
-
- : FDUP
- [ $D9 $C0 ] ( FLD ST )
- ;
-
- : FOVER
- [ $D9 $C1 ] ( FLD ST(1) )
- ;
-
- : SQRT ( SQRT(ST) --> ST )
- [ $D9 $FA ] ( FSQRT )
- ;
-
- : PI ( PI --> ST )
- [ $D9 $EB ] ( FLDPI )
- ;
-
- : F0 ( 0 --> ST )
- [ $D9 $EE ] ( FLDZ )
- ;
-
- : F1 ( 1 --> ST )
- [ $D9 $E8 ] ( FLD1 )
- ;
-
- : setdecimals ( n -- )
- >TX
- >dx 18 - dplp !
- %1
- TX> , 1 do
- %10 F*
- loop
- scale F!
- TX> , 0 .=. IF %1 scale F! ENDIF
- ;
-
- : getdecimals ( -- n )
- dplp @ >dx 18 -
- ;
-
- : finit ( -- )
- [ $9B $DB $E3 ]
- 3 setdecimals
- ;
-
-
- : <F# ( n -- )
- 0 ldz c!
- pad bx+ bx> fhld !
- ;
-
- : F# ( n -- )
- { >R , $000F and .0=. pushf ldz c@ .0=. .and. .not. R> }
- IF
- FHLD @>bx c!
- FHLD INC
- 1 ldz c!
- ENDIF
- ;
-
- var start word ;
-
- : #F> ( n -- )
- pad bx+ bx>dx fhld @ - pad c!
- ;
-
- : bcd>asc
- [ $88 $C4 $80 $E4 $0F $24 $F0 $C0 $E8 $04 $05 $30 $30 ]
- ;
-
-
- : nbcd
- ( offset ax asc)
- ( bcd base bx -- )
- minus , 18 +
- push , 1 and
- 0=IF
- pop u2/ >bx+ c@ bcd>asc F#
- ELSE
- pop u2/ >bx+ c@ bcd>asc [ $88 $E0 ] F#
- ENDIF
- ;
-
-
-
- : bcd>$
- bx>tx
- <F#
- tx>bx
- 9 >bx+ c@ 0=IF '-' FHLD @>bx c! FHLD inc endif
- dplp @ , 1 do
- I tx>bx nbcd
- loop
- ldz c@ , 0 .=. IF 1 ldz c! '0' F# ENDIF
- dplp @ , 18 .=. .not. IF
- '.' F#
- dplp @ 1+ >dx 18 do
- I tx>bx nbcd
- loop
- ENDIF
- #F>
- pad
- ;
-
- : F>$
- scale F@ F*
- bcd FBCD! bcd bcd>$
- ;
-
- : F.
- F>$ count type
- ;
-
-
- dictionary
-
- : main
- >default
- ." NAXOS Floating-point: Die Zahl π : " cr cr
-
- FINIT
- 17 , 0 do
- I setdecimals
- ." Dezimalstellen : " getdecimals , 2 .r ." "
- PI F. cr
- loop
- cr
- ." Beachten Sie die richtigen Rundungen am Ende der Zahl !"
- cr
- wait
- 10 , 0 do cr loop
- cr
- ." Die Quadratwurzeln von 0 .. 16 " cr cr
- 16 setdecimals
- 16 , 0 do
- ." √" I push , 2 .r ." = " FIPOP sqrt FDUP F.
- ." √² = " fdup f* f. cr
- loop
- cr
- ." Wenn Sie nur Nullen sehen, laden Sie aus DOS den Emulator EM87 !"
- cr wait
- ;