The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 10:06 PM
Simple C question... Hopefully it's simple Xeed High Level Programming 6 12-15-2006 02:29 PM
Shell script fundamental Questions pankajkrmishra Shell Programming and Scripting 2 07-21-2006 02:14 AM
Simple if GNMIKE Shell Programming and Scripting 2 12-04-2005 06:54 AM
Ok simple question for simple knowledge... Corrail UNIX for Dummies Questions & Answers 1 11-28-2005 01:03 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 06-29-2002
shamal shamal is offline
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
  #2 (permalink)  
Old 06-29-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #3 (permalink)  
Old 07-01-2002
linuxpenguin's Avatar
linuxpenguin linuxpenguin is offline Forum Advisor  
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
  #4 (permalink)  
Old 07-29-2002
Perderabo's Avatar
Perderabo Perderabo is offline Forum Staff  
Unix Daemon
  
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,111
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.
  #5 (permalink)  
Old 08-14-2002
casinokev casinokev is offline
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!
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 02:59 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0