View previous topic :: View next topic |
Author |
Message |
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Jun 25, 2004 11:03 am |
|
|
I will try the code tonight.
Looking at the faster way...
Code: | #else // faster way
quot2 = val.w[1];
val2.d = quot2 * 4295;
// 16 bit answer is val.w[1]
#endif |
Should the 16 bit answer be in val2.w[1]? |
|
|
future
Joined: 14 May 2004 Posts: 330
|
|
Posted: Fri Jun 25, 2004 7:38 pm |
|
|
Running ok.
speed went from ~1070 to ~1500 loops/second.
size down 70bytes.
a sample calculation with old routine equals to 195, new routine 198. |
|
|
SteveS
Joined: 27 Oct 2003 Posts: 126
|
|
Posted: Mon Jun 28, 2004 8:25 am |
|
|
Yes val2.w[1] - sorry 'bout that.
On the error; the faster way may cause some truncation error. I thought the method I proposed would not cause a problem. I just simulated it on a PC and found no values that differed by more than 1 digit in the answer. Strange. Have you tried a variety of input values to see if the errors are widespread? And what should have been the correct answer?
- SteveS |
|
|
Futureatwork Guest
|
|
Posted: Wed Jul 14, 2004 9:28 am |
|
|
Hello SteveS,
I (we?) got some more work to do.
Code: | int8 interp16(int16 x1, int16 x2, int8 y1, int8 y2, int16 x) {
int32 n;
int16 x21,dx,r;
if (x<=x1) { return(y1); } // below or equal lower bound
if (x>=x2) { return(y2); } // above or equal upper bound
dx=x-x1;
x21=x2-x1;
if(y2<=y1) { // negative slope
r=y1-y2;
n=dx*r;
r=n/x21;
return(y1-r);
} else { // positive slope
r=y2-y1;
n=dx*r;
r=n/x21;
return(y1+r);
}
} |
This routine does interpolation in 8bits based in 2 16bit values.
It works fine but I think it deserves some optimization if possible.
Almost all the time is lost in īnī and īrī calculation. |
|
|
|