Advertisement

Is there a PATTERN in these numbers???

Started by October 08, 2002 10:27 AM
18 comments, last by Timbo_M45 22 years, 4 months ago
I''m not much of a programmer, but are exponential calculation faster than square roots? If so, use x to the power of 1/2 rather than square root.
Check out Drunken Brawl at http://www.angelfire.com/games6/drunken_brawl!
quote:
Original post by gamechampionx
I''m not much of a programmer, but are exponential calculation faster than square roots? If so, use x to the power of 1/2 rather than square root.


No they''re not. If they were, sqrt would be implemented that way to begin with.
Advertisement
Tkae a look at this page on approximating square roots. It may offer a faster solution than your current method.

Actually, square roots are not done in hardware, they are only done computationally in software libraries. This is the case for x86 and most desktop machine processors.
quote:
Original post by Anonymous Poster
Actually, square roots are not done in hardware, they are only done computationally in software libraries. This is the case for x86 and most desktop machine processors.



WTF ?!

The FSQRT instruction has been implemented in hardware since the 8087 co-processor (for the x86/x87 family) and all nowadays processors have a FPU.
yea, yea.
theres a hardware sqrt intrustion
I think theres a FPU and a SSE one, with the SSE one being really fast.

Bugle4d
~V'lionBugle4d
Advertisement
I don''t see any other way to speed up the sqrt method other than what people have given you. Apparently your trying to find the distance between p2x and p2y. While its not nearly as accurate, have you thought about the "taxi cab method"?

R = abs(p2x) + abs(p2y)

this is much faster, but only good if you want an approximation

Maybe something obvious, but I don''t know...

What do you do with R?

If you use it for further calculation, you could try "pulling" the sqrt out to as far to the end as possible.

If you use it for comparison, just square the other half of the comparison (like, for example, when you want to compare the lengths of two vectors).

Ciao, ¡muh!
They're watching us...
Yes there is a pattern to the numbers using the R = Sqrt((p2x * p2x) + (p2y * p2y)) equation.

See if you get my meaning.

R1 = 1.4142135623731
Scale_for_ones = 1.1180339887498910013554043555145

R1 * (1.1180339887498910013554043555145 * (p2y - 1)) = anything for| p2x = 1, p2y = 2: R = 2.23606797749979 through p2x = 1, p2y = 63: R = 63.0079360080935 |



R2 = 2.23606797749979
Scale_for_twos = 1.2649110640673515174130944522319

R2 * (1.2649110640673515174130944522319 * (p2y - 1)) = anything for| p2x = 2, p2y = 2: R = 2.82842712474619 through p2x = 2, p2y = 63: R = 63.0317380372777 |


I haven't tested other senerios yet, but it looks good so far.


[Edit]
I missed some "()'s" in there.
[/Edit]

[edited by - thewayout_is_through on October 16, 2002 9:03:53 PM]
"Who are you, and how did you get in here?""I''m the locksmith, and I''m the locksmith."
The mathematical fact of the matter is that no finite amount of multiplications and divisions can completely replace the square root. This is because multiplication and division will only produce rational numbers out of rational numbers, whereas square root often produces irrational numbers.

That said, there are certain approximations that you can make (such as the first few terms of a taylor series), but if I recall correctly they will only apply over certain ranges, and you''ll need more than 5 multiplications to get a decent approximation anyway.

As noted above, sometimes you don''t actually need to take a square root (such as when you''re comparing distances), or by caching distances. If you need to use a square root, then use it. There are probably other parts of your program that need optimisation.

This topic is closed to new replies.

Advertisement