home .. forth .. misc mail list archive ..

Bug in my F21 integer square root routine



Dear Jeff,

I found a ?minor? bug in my integer square root routine.
I mistakenly used com and thought negate.  The corrected
routine follows.

Sorry about that,
Mark

P.S. The new emulator is very nice, but you should
mention that it needs EMS memory enabled (not the default
on my WindowsNT machine).  It took me awhile to figure this
out since the window disapears too quickly to read the error
message.

\ F21 20 bit Integer Square Root

': sqi ( xr --- xr |a=t )
dup com A nop        \ xxr>-xxr>t-xxr
+ -if                \ fxr
push over pop nop    \ xr|f>rxr|f>frxr|
+ -if                \ fxr
com push drop A      \ x'xr>xr|x'>r|x'>tr|x'
2* nop nop nop       \ tr|x'
+ pop dup nop        \ r'|x'>x'r'>x'x'r'
then
then
drop push 2/ pop     \ xr>r|x>r|x>xr
A 2/ 2/ A!           \ txr>txr>txr>xr
;'

': isqrt   ( x --- x )
a push 40000 # a!    \ ax>x|a>tx|a>x|a
push 0 # pop nop     \ |xa>r|xa>xr|a
sqi
sqi
sqi
sqi
sqi
sqi
sqi
sqi
sqi
over com nop nop     \ -xr>r-xr >>> was: com over nop nop
+ com nop nop        \ -fr>fr   >>> was: + -if
-if                  \ fr       >>> new: line
drop 2 # nop nop     \ r>2r
+ dup nop nop        \ r>rr
then
drop 2/ pop a!       \ r
;'----