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 CCS Technical Support

Calculations on large numbers

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Tom Jetland



Joined: 23 Jun 2011
Posts: 31
Location: UK

View user's profile Send private message

Calculations on large numbers
PostPosted: Fri Jul 08, 2011 5:34 am     Reply with quote

Hi,

I'm getting 3 simultaneous values from a sensor as signed ints with a max value of 650,000 (decimal).

I need to perform the following function on them: -

result = SquareRoot( (a^2) + (b^2) + (c^2))

Just to get started I used floating point numbers, but because I need very high precision and repeatability I know that I'll have to used integers.

How do I deal with numbers in the 64 bit range, i.e. the value I would get when squaring the 650,000?

I've looked around at the GNU big number libraries, but to be honest, I had a job understanding it!

Any input would be much appreciated!

I'm using a PIC18F4620.

Tom
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Jul 08, 2011 6:01 am     Reply with quote

Unless I was going to do a lot of other math with these big numbers I would write my own function to take 3 32 bit ints and return a 32 bit int using a 48 bit intermediate result. The square root is the only thing that would be difficult.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
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