CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

How to handle multiplication overflows?
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
future



Joined: 14 May 2004
Posts: 330

View user's profile Send private message

PostPosted: Fri Jun 25, 2004 11:03 am     Reply with quote

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

View user's profile Send private message

PostPosted: Fri Jun 25, 2004 7:38 pm     Reply with quote

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

View user's profile Send private message

PostPosted: Mon Jun 28, 2004 8:25 am     Reply with quote

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







PostPosted: Wed Jul 14, 2004 9:28 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group