![]() |
Re: Basic Math Help
Quote:
y = 1.5x = (15x)/10 but not y = x^2 != x^(20)/10 Hmm, one way around this is to take the log of both sides: log y = 2 log x = (20 log x) / 10 or y = 10^((20 log x) / 10) Be nice to your CPU and give it lookup table and don't be a precision junkie ;) Jason |
Re: Basic Math Help
Oh yeah... wow. haha ... i totally didn't take into account that POW might be non-linear. That was dumb.
|
Re: Basic Math Help
Quote:
From the pow(3) man page: Code:
double pow(double x, double y); |
Re: Basic Math Help
Oh okay.... I thought POW was just some function they made up
|
Re: Basic Math Help
Quote:
|
Re: Basic Math Help
I'd suggest avoiding floats like the plague on these controllers; the floating point precision just is NOT there.
|
Re: Basic Math Help
Your question has prompted a number of different replies, and touches a wide range of topics... Of couse, I will toss in my 2 cents.
The floating point math should be working, so my first question is, "How do you know what the resulting value really is?" I ask this because the [C18] printf function is very lame about displaying floating numbers. I usually scale the number I am interested in, and cast it to an "int" in the printf function call. In C18 a float and double are both implemented using IEEE-754 floating point standard; they are the same. One thing to remember about floating point isn't its accuracy, but its wide dynamic range that make it handy... The chip used in the RC has a built-in 8x8 multiply unit, which makes all math operations faster. It turns out that scaling to long data types, and multiplying and dividing with integers can actually take longer to execute than a simple, single floating point calculation. I urge everyone to do a little test. At the start of your main code set an RC digital output high, then after it is finished clear the bit. Put an oscillscope on the output pin and see how long your code is really taking to execute. We have some fairly heavy-weight objects in our code, and it takes about one millisecond to execute. I don't think that anyone will run out of computing power for the FIRST application. Regarding your specific problem, I would recommend unbundling the one huge equation into several smaller ones using intermediate variables along the way. This way you can use [scaled int] printf's on the values to see how the calculation progresses. I hope this helps, Jim |
| All times are GMT -5. The time now is 15:17. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi