Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Square root function in Forth using x86 Assembly?

I don't know much about assembly, but I am pretty sure that there are square root instructions on the x86? I am trying to get a square root function to work well in froth and the one that I have found gets bogged down somehow when I run it many times.

: sqrt-closer ( square guess -- square guess adjustment)
2dup / over - 2 /
;

: sqrt ( square -- root )
1 begin
sqrt-closer dup
while + repeat
drop nip ;
like image 425
Will Avatar asked Jan 16 '10 07:01

Will


2 Answers

Look here:

http://www.azillionmonkeys.com/qed/sqroot.html

Everything you ever wanted to know about square roots, but were afraid to ask. Contains an implementation in x86 assembly language.

like image 143
Robert Harvey Avatar answered Sep 22 '22 23:09

Robert Harvey


There is a floating-point square root instruction (FSQRT). This is quite fast, even if you only need an integer square root.

like image 33
Artelius Avatar answered Sep 20 '22 23:09

Artelius