The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Simple to you not simple to me pattern matchin help aleks001 Shell Programming and Scripting 0 07-22-2007 07:06 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 10:29 AM
Shell script fundamental Questions pankajkrmishra Shell Programming and Scripting 2 07-20-2006 11:14 PM
Simple if GNMIKE Shell Programming and Scripting 2 12-04-2005 02:54 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 09:03 AM

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-28-2002
Registered User
 

Join Date: Sep 2001
Location: El Net-3L Academy,NO. 69, Rd. 19(Old), 9A(New), Dhanmondi,Dhaka, Bangladesh-1209.
Posts: 6
Post a simple fundamental

long double p;
long double q;

how could i find and store the sum of p & q ? where p and q might have their maximum value.

i hope, i'd get a lot of solutions.

-sham
__________________
u help me, He'll help u.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 06-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,354
When you want to exceed the maximum value of the largest data type that a language has, you have a clear path to follow: invent your own data type. You will need to write routines to convert long double to and from your private data type. You will need to write your own routines to add to elements of your private data type. And you will need to write your own routines to display the values of your private data type.

The bad news: none of this is easy and it probably cannot be written portably. The good news: your private data type can take many forms, so there are indeed a lot of solutions.
Reply With Quote
  #3 (permalink)  
Old 07-01-2002
linuxpenguin's Avatar
Registered User
 

Join Date: May 2002
Location: India
Posts: 295
Talking Re: a simple fundamental

Hi,

The simplest way i feel is to do this using two arrays. One for p and another for q. Store each digit of p in one array and of q in another. Add every element from the last index of array and put the sum in the same index of a third result array (or u can use one of the two arrays itself as the result array) hold the carry in a temporary variable and use this one to add to the next indices of the array.


Well, this in itself is the algorithm. Your way is easy now, i guess. If you are thru with this one, try multiplication of two such numbers
__________________
War doesnt determine who is right, it determines who is left
Reply With Quote
  #4 (permalink)  
Old 07-29-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,354
The fastest algorithms for calculating floating point numbers to tens of thousands of digits involve Number Theoretic Transforms. But I thought that only a few special purpose program had been written that use them. But I have just found APFLOAT: A C++ High Performance Arbitrary Precision Arithmetic Package. The claims that the author makes for this package are jaw-dropping:
Quote:
A sample program for calculating pi is included in the package. With 128MB RAM and about 700MB free disk space you can calculate more than 100 million digits of pi. Calculating one million digits of pi takes less than two minutes with a 400 MHz Celeron. This makes it one of the fastest programs for calculating pi (faster than the Japanese super_pi program).
If you really need highly precise floating point numbers this package may be worth checking out.
Reply With Quote
  #5 (permalink)  
Old 08-13-2002
Registered User
 

Join Date: Aug 2002
Location: Boise, ID
Posts: 1
You might also try the GNU MultiPrecision library. I don't know how it compares to the APFLOAT: A C++ High Performance Arbitrary Precision Arithmetic Package that Perderabo mentioned, but it might be worth a shot. The site is http://swox.com/gmp/
Good Luck!
__________________
Regards,

casinokev
Reply With Quote
Google UNIX.COM
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 05:32 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0