In article <nnd$0729bd17$4f184982@a8d623d456fa3140>,
Hans Bezemer <
the.beez.speaks@gmail.com> wrote:
This time, we delve into a forgotten way to handle fixed point
arithmetic. Which IMHO deserves to be dusted off now we entered the
64-bit era!
https://www.youtube.com/watch?v=VwPForQL10Y
A one screen fixed point:
----------------------
( *s /s fix-scale -fixedpoint- ) \ AvdH C3nov06
WANT ALIAS
8 CELLS 4 - CONSTANT fix-scale \ n represents n.2^-scale.
1 fix-scale LSHIFT CONSTANT 1/1
1 fix-scale 1- LSHIFT CONSTANT 1/2
\ As */ * / but scaled.
: */s >R UM* R> UM/MOD NIP ;
: *s 1/1 */s ; : /s 1/1 SWAP */s ;
\ Most other operators remain the same:
'+ ALIAS +s '- ALIAS -s '*/ ALIAS */s
\ For a RATIO (n/d) return an equivalent scaled NUMBER.
'/s ALIAS rat>s \ By accident.
\ Print a scaled double number
: .mantissa 0 DO BASE @ 1/1 */MOD &0 + EMIT LOOP DROP SPACE ;
: _D.s 1/1 UM/MOD 0 <# #S #> TYPE &. EMIT 20 .mantissa ;
: U.s 0 _D.s ;
--------------------
For ISO replace '+ by ' + or ['] + .
(I can't remember which is which.)
ALIAS gives a new name for an old thing.
In a pinch do
: */s */ ;
WANT signifies that you want ALIAS if it isn't loaded already.
Hans Bezemer
--
Temu exploits Christians: (Disclaimer, only 10 apostles)
Last Supper Acrylic Suncatcher - 15Cm Round Stained Glass- Style Wall
Art For Home, Office And Garden Decor - Perfect For Windows, Bars,
And Gifts For Friends Family And Colleagues.
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)