Lets make a game...
You should welcome constructive criticism from others, it''s a significant aid to improving code (and many other things). In fact it''s probably the most significant aid since (in my experience) many people get stuck in coding ruts and, without someone else''s help, rarely uncover their own flaws.
Further to what Dobbs posted, in general, try to avoid the ''=='' and ''!='' operators when used in conjunction with floating point values. I always use this code to demonstrate why those operators are dangerous with floating point values:
Try the above and see what happens. Then work out why.
Skizz
int main (int argc, char *argv){ for (float value = 0.0f ; value < 2.0f ; value += 0.05f) { printf ("Does %.02f == 1? %s\n", value, value == 1.0f ? "Yes" : "No"); } return 0;}
Try the above and see what happens. Then work out why.
Skizz
when we are talking about square roots you could use a large lookup table to get the values you want
of course precision suffers a bit but who cares about precision
take a 2 mb chunk of your memory for the lookup table and you should be able to get squareroots from 0-2000 with a precision of 0.001
of course precision suffers a bit but who cares about precision
take a 2 mb chunk of your memory for the lookup table and you should be able to get squareroots from 0-2000 with a precision of 0.001
2mb? You''d have to be nuts about your lookup table to use so much memory for it .
The way I see it
(0-2000)
100 * 2001 * 4 (float) / 1024 = ~781.25kb
Which still seems like quite a bit for a lookup table, it would probably be better to reduce precision by 10 to get it to 78.13kb
Although that is still quite a bit, there are a number of ways to optimize the memory while inflicting a smaller calculation cost. (i.e. do you really need a float to store a number thats 0-2000?)
Since we are all in a mood for constructive critism .
-------
Homepage: http://students.washington.edu/andrey
The way I see it
(0-2000)
100 * 2001 * 4 (float) / 1024 = ~781.25kb
Which still seems like quite a bit for a lookup table, it would probably be better to reduce precision by 10 to get it to 78.13kb
Although that is still quite a bit, there are a number of ways to optimize the memory while inflicting a smaller calculation cost. (i.e. do you really need a float to store a number thats 0-2000?)
Since we are all in a mood for constructive critism .
-------
Homepage: http://students.washington.edu/andrey
quote:Original post by Basiror
when we are talking about square roots you could use a large lookup table to get the values you want
of course precision suffers a bit but who cares about precision
take a 2 mb chunk of your memory for the lookup table and you should be able to get squareroots from 0-2000 with a precision of 0.001
2MB lookup table? are you sane? Ever heard about caches ?
With intrinsic functions enabled sqrt() or sqrtf() will generate something like:
fld var
fsqrt
fstp var
which takes about 80 clock cycles on a Pentium 3
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement