|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
code efficiency
I've got a little problem: as a part of the joystick program i need to use Pitagoras'es formula, which means square root/ each time iv'e tried using it I got an error, so I thought of a lookup table. the prolem is that the lookup table will b 65,000 values long.
whar will be better- using the function, the big tble, or mabe using some simple trigonometry which requires just one lookup table 90 values long? help please. also- if you could send me a picture of the three alibration colors- red, green and yellow- it'd be really wonderful for my teams- we're Israelis, and to buy a paint color we need to choose it manually- not by its colorants. thanks in advanse |
|
#2
|
|||||
|
|||||
|
Re: code efficiency
Quote:
If the result is going to be used as an integer, you can use a much smaller lookup table. Since many inputs will yield the same output, you can actually make a table of squares and search through it (using a binary search will keep it short). |
|
#3
|
||||
|
||||
|
Re: code efficiency
If you need a square root function you can use this:
Code:
int intRoot(unsigned int value)
{
unsigned int result = 0;
unsigned int multiplier;
unsigned int backup;
int loopint;
for (loopint = 7; loopint >= 0; loopint--)
{
multiplier = 1 << loopint;
backup = result;
result |= multiplier;
if (result * result > value)
result = backup;
}
if (value - result * result > abs(value - ((result + 1) * (result + 1))))
result++;
return (int)result;
}
|
|
#4
|
||||
|
||||
|
hry thanks!
acualy, i've just replaced my 65,000 table with one just 520 valuse long, but it was still too much for my bot thanks again BTW- your code has just sved me from an nervous breakdown ))))))))))))my team has just discovered that our arm won't rise... and I don't seem to care at all... surely it's just all these sleepless nights trying to get me...(need sleepy smiely... ) Last edited by Anton : 13-02-2005 at 15:04. |
|
#5
|
||||
|
||||
|
general question
another thing: what is better, generaly, a lookup table or just a function?
i know it's a bit too general, but still... |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Example gyro code released. | Kevin Watson | Programming | 60 | 17-03-2005 18:32 |
| Updated: Serial Port Driver Code | Kevin Watson | Programming | 4 | 05-02-2005 18:39 |
| Team THRUST - Kevin's Code and Camera Code Combine | Chris_Elston | Programming | 3 | 31-01-2005 22:28 |
| Sourceforge for Code Repository and other stuff | SilverStar | Programming | 9 | 15-01-2005 21:16 |
| heres the code. y this not working | omega | Programming | 16 | 31-03-2004 15:18 |