Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

MindWipe

Really, really fast sqrt (not Carmacks)!?!?!?

This topic is 5446 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Okey... I''m trying to do a raycaster in j2me, now I stumbled uppon a problem. I need a pretty damn fast sqrt. Or an sqrt for that matter (not one being supported). Camrmack''s sqrt won''t work because j2me does not support floating points (or doubles). Anyone got any idea?!?! I might make a lookup table but that will take alot of memory... It doesn''t have to be too accurate at all. /MindWipe

Share this post


Link to post
Share on other sites
Advertisement
no floats? so.. fixed point? sorry, i don''t know much about the platform you use..

but.. if you have an unsigned integer, and take the square root of it, it''ll be an unsigned short.. means a 4byte value will have a 2byte root..

that could help for a lookuptable.. or not.. dunno:D i''m tierd.. sorry..

but there are tons of algorithms for all sort of constraints out there (even without multiplication and addition supported, etc:D)..

just use google..

"take a look around" - limp bizkit
www.google.com

Share this post


Link to post
Share on other sites
Do you have to calculate the square root? If you are doing something like comparing distances you can just compare the squared value. Of course, I don''t know exactly what you are doing.

Share this post


Link to post
Share on other sites
quote:
Original post by CodeMunkie
Do you have to calculate the square root? If you are doing something like comparing distances you can just compare the squared value. Of course, I don''t know exactly what you are doing.


Well, I''m using it to get a distance. But I think I''ll use some sort of table. Because the sqrt is only needed so that I know which value out of 96 to choose, hence it hasn''t got to be that exact.

/MindWipe

Share this post


Link to post
Share on other sites
Wouldn''t it be possible to do it the other way arround? Store the 96 sqared border values and search the right one in this using a binary search?

Share this post


Link to post
Share on other sites
You''re using some equations that involve a square root. Can you manipulate them by squaring both sides to eliminate the need for a square root? The simple example is, replace ''sqrt(x)==2'' with ''x==4.'' I''m sure it''s not that simple, but you might be able to reduce your dependance on sqrts!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Roland: Binary search? In that case, why not use direct mapping?

/__fold

Share this post


Link to post
Share on other sites
What do you mean by direct mapping?
A lookuptable can't be used for squared values, because the table would become too big and the the distance between the values increases, so you cant use a constant scaling factor.

p.s. take a look at: http://www.azillionmonkeys.com/qed/sqroot.html
there are some sqare root algorithms described

[edited by - Roland on August 12, 2003 6:27:26 PM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Roland: You''re right, I''ll go to bed now.

...or how about a hash map?

/__fold

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!