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
Help required on Shell Programming! udiptya UNIX for Dummies Questions & Answers 7 01-31-2008 03:38 AM
Urgent : Help required V3l0 AIX 2 01-11-2008 07:37 AM
Urgent help required umanglalani Shell Programming and Scripting 1 04-12-2007 12:24 AM
Urgent Help required rahul26 UNIX for Dummies Questions & Answers 1 08-16-2006 10:23 AM
Urgent help required with uname() rm1 High Level Programming 2 02-23-2005 06:18 PM

Reply
 
Submit Tools LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-31-2002
Registered User
 

Join Date: Oct 2001
Posts: 3
Stumble this Post!
Exclamation C programming - Urgent help required

Hi,

I am writing a small 'C' program to add very large floating point numbers. Now the program should be capable of adding the maximum floating point number that is possible on Sun Solaris machine.

Can some let me know whether there is any extra logic that needs to applied for making sure that the program can handle addition of largest floating number that a machine allows.

Thanks,

Last edited by kkumar1975; 03-31-2002 at 10:38 AM.
Reply With Quote
Forum Sponsor
  #2 (permalink)  
Old 03-31-2002
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Washington DC Area
Posts: 8,425
Stumble this Post!
You might want to read this. But the quick answer is as long as you don't overflow, you're ok.
Reply With Quote
  #3 (permalink)  
Old 04-08-2002
Registered User
 

Join Date: Feb 2002
Location: Brabant, Belgium
Posts: 65
Stumble this Post!
If you suspect that your variable may overflow, then I suggest you assume it will.
In programming, Murphy's law is a law of nature :-)
In this case, it would state that 'if a variable _can_ overflow, then there is a 100% chance that it _will_ overflow'

I do not know the actual implementation of floating point under Solaris or other 64 bit OSes, but it would make sense to assume that they are 64 bits in length. This is quite easy to find out, so I assume you will if you don't already know.

Before reading any of this, look for a bignum library, that may have what you need.


If a double is stored in 64 bits, then you could overcome the problem by creating your own 128bit bigfloat

struct bigfloat {
long m; // Mantissa
long e; // Exponent
};

and define the operations you need on bigfloat:

bigfloat bigfloat_add(bigfloat a, bigfloat b)

etc.

This is only one of several approaches, another is to not use float at all, but BCD or even arbitrary length strings.

I don't know what it is that you want to do, if it is some scientific experiment, then just disregard the rest of this.

But in certain applications the use of floating point is illegal!

If I am not mistaken these include safety-critical applications and accounting systems.
__________________
PS
All of the above is to be read as '... unless I am wrong'
ENDPS
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools
Display Modes




All times are GMT -7. The time now is 12:39 AM.


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