Say I have a DWORD in EAX, and I need to calculate its root.
So, what do I do? (I'm wondering)
Well, I could try to divide (SHR EAX, ), and compare both results, until I get something similar.... okay, that?s all that I?ve come up to.
But I?m sure there?s a better way.

Can you show me a snippet or just give me a hint.

(I know, this is plain basic arithmetic, the same that my small syster would solve, but I just can see a solution....):stupid:
Posted on 2002-06-18 10:56:10 by slop
something like this would do it

SquareRoot PROC Number:DWORD

mov ecx, 1
@@: inc ecx
mov eax, ecx
mul ecx
cmp eax, Number
jb @b
ja @f
mov eax, ecx
@@: xor eax, eax
SquareRoot ENDP
Posted on 2002-06-18 12:02:19 by Kudos
Thanks a lot, Kudos, exactly what I was looking for :)
But what can I do if i have a DWORD ( I mean a big one)
that would take ages... and it?s inside a vectorial thingy, that means hundreds of them done at runtime, is there anyway to do it without floating point?
Posted on 2002-06-18 12:09:19 by slop
There is a shift method, binary search and a table lookup method ... You might want to check/research on this. I think there is a K3D and SSE implementation, try google. :)

Why Not FPU? Life would be much easier... :)
Posted on 2002-06-18 12:25:53 by stryker
you can make the algo much faster..
dont start from one .

but you should use fpu much faster and smaller code(i think)
Posted on 2002-06-18 13:09:41 by eko
Posted on 2002-06-18 13:13:03 by bitRAKE

There is a shift method, binary search and a table lookup method ... You might want to check/research on this. I think there is a K3D and SSE implementation, try google.

1) The shift method looks OK

2) The binary search, how can I do that?

3) The table lookup? You mean search in the lookup... but then i need to code in an external .inc file all the possible values, is that?
---------------------------quote by stryker----------------------------------------
Why Not FPU? Life would be much easier...

-----------------and by eko-----------------------------
you can make the algo much faster..
dont start from one .
but you should use fpu much faster and smaller code(i think)

Okay, maybe i?ll guve it atry , have any idea?
Thanks you two.
Posted on 2002-06-18 13:16:46 by slop
Wow, you really got it goin'!!

A very interesting algo going on bet2ween CodeLover & you, then Hels great idea,with The Svine's explainning bitRackness, like a good tragedy with its moments of comedy, then the3 lines float by dxantos (though I?ll have to check the intel manual even for that ;) to end up with Arne Steinarson?s code also...extenuating ;). ), and then the place:
I wouldn?t have gotten it in a zillion monkey googles (I think, what?s his name? Mike Googles, doesn?t like me, he always points to unknown places ;) )

bitRAKE, I owe you one, ;)
Posted on 2002-06-18 13:30:26 by slop
I found it :) http://www.azillionmonkeys.com/qed/sqroot.html

oh!!! shoot ... bitrake's thread already has the link... :grin: I should have read that thread thoroughly.
Posted on 2002-06-18 13:42:31 by stryker
Okay now I?ll thank everybody:

Kudos, stryker, eko, bitRake

(okay also, CodeLover, Hel, dxantos, Silver,....)

And here I have square-root algos until i?ll have grandsons :)
Posted on 2002-06-18 13:50:44 by slop
use trig or Pythagoran theorem

make the number you want the root of the hypotenuse of a right angle triangle with the other two sides equal then apply DeMoivre's theorem.
Posted on 2002-06-18 16:36:02 by IwasTitan
I can not believe that at least one person from this board did not see my con in the last post.

are there no math experts here
Posted on 2002-06-19 23:51:19 by IwasTitan
I suggest you ponder the following facts:

1: 'Experts' don't like to waste time on obvious nonsense.
2: The guy who started the thread already got what he wanted, so he didn't need to be warned off from your nonsense.
3: Your first act in this thread was an attempt at desinformation...

The last point doesn't improve your standing here at all.
If you go too far down that road, the moderators may act.
Posted on 2002-06-20 15:29:00 by RAdlanor
I second what RAdlanor said, and add that in fact this forum is not to show that one is a smartass, but to genuinely and humbly help others.

Posted on 2002-06-20 16:25:04 by Maverick
ok...ok ...sorry...humble apologies

I just wanted to see if anyone realized that even if you used DeMoivres theorem you would still have to have an algo to find a square root which is what you wanted in the first place.

You guys act like a major sin was committed the way your coming down on me. Look at the hostility in your own words.

"from your nonsense"

"an attempt at desinformation"

"is a smartass"

Gee i feel like a Nazi after all those comments.
Posted on 2002-06-20 19:04:54 by IwasTitan
just read the last post and wondered what Nazi has to do with it.. :confused:

...but OK..

Posted on 2002-06-21 11:09:30 by NOP-erator
No way, nazis don know how to code ;)

Maverick and Radlanor are right, I was looking for an easy algo, bitRAKE showed me the link, and that's it... great, because I was stuck, and quick also.

Now, I've never heard about DeMoivre (sorry, I'm not a mathemagician ;) ), but if you know a nice algo using his method and you feel like posting it here, feel free to do it.
It always interesting to learn new stuff :)
Posted on 2002-06-21 11:47:37 by slop
fjrp2 is right, if you're such an expert, why don't you dare an attempt to explain us your idea in detail?

Posted on 2002-06-21 12:02:00 by NOP-erator
IwasTitan: please don't get me wrong, I didn't call you a smartass, but I've seen some here, and I was referring to that. Nothing personal, I don't know you. You're welcome, and please as other already said feel free to contribute with your knowledge, it will be appreciated by many, I'm sure.
Posted on 2002-06-21 16:51:55 by Maverick
IwasTitan ,
I did not 'come down' on you, but merely pointed out that your post was inappropriate. Had I really thought you meant any harm by it, then I might have 'come down' on you, in an entirely different manner.

I notice that you object to two of my phrases, which surprises me.

One is: "from your nonsense". Used by me about your first post.
Yet you yourself also know it to be nonsense, since you expected those who know math well to notice that it wouldn't solve anything. (You just don't use trigonometry for square roots.)

The other is: "an attempt at desinformation"
But you told a guy, who needed info, to use a method that you knew as incorrect. By definition, that is 'desinformation'.

But don't get me wrong now, again ;)
I have no hard feelings, as I realize that you were just kidding, though I still think you shouldn't do that this way, in threads where someone needs help. Save it for the 'Heap' instead.
Posted on 2002-06-22 02:29:08 by RAdlanor