Okay,

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:

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:

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

ret

@@: xor eax, eax

ret

SquareRoot ENDP

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?

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?

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... :)

Why Not FPU? Life would be much easier... :)

you can make the algo much faster..

dont start from one .

but you should use fpu much faster and smaller code(i think)

dont start from one .

but you should use fpu much faster and smaller code(i think)

When in doubt search:

http://www.asmcommunity.net/board/index.php?topic=3276&highlight=square+root

http://www.asmcommunity.net/board/index.php?topic=3276&highlight=square+root

stryker:

---------------------quote------------------------------------------

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.

---------------------quote------------------------------------------

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.

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:

azillionmonkeys.

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, ;)

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:

azillionmonkeys.

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, ;)

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.

oh!!! shoot ... bitrake's thread already has the link... :grin: I should have read that thread thoroughly.

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 :)

Kudos, stryker, eko, bitRake

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

And here I have square-root algos until i?ll have grandsons :)

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.

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.

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

are there no math experts here

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.

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.

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.

Hejd

Hejd

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.

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.

just read the last post and wondered what Nazi has to do with it.. :confused:

...but OK..

-NOP-

...but OK..

-NOP-

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 :)

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 :)

fjrp2 is right, if you're such an expert, why don't you dare an attempt to explain us your idea in detail?

regards,

-NOP-

regards,

-NOP-

**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.

**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.