Thread: Adding Large float values--need help

  1. #1
    Registered User
    Join Date
    Mar 2002
    Posts
    9

    Adding Large float values--need help

    Hi,

    I am searching for the solution of following question:

    " Write a program in 'C' language to add very large floating-point numbers. The floating point number may be equal to maximum floating point number that is possible on your machine".

    I was told that it is not possible. But still my instincts are saying, it might be possible. Any suggestions and information to the links are welcome.

    Thanks in advance.

    bye,
    vaspro

  2. #2
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Do you mean the numbers that are to be added can be up to the limit of floating-point values or the final sum or the numbers can be up to the limit. Hav you tried it yet?

  3. #3
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    the numbers to be added are upto the maximum floating point number. Not the final sum :-).

    Vaspro

  4. #4
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    But what problems are there if you don't exceed the limit?

  5. #5
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    if

    s=x+y;

    both x and y are to be the maximum possible floating point numbers on your system.

    As per my knowledge it is not possible with simple arthimetic operators. We need to use some loagic with linked lists or so. Some similar operation is adding two polynomials.

    I think now my question is clear.

    --vaspro

  6. #6
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    There are several ways to do this. You need to design your own datastructure and it's operation functions.

    > We need to use some loagic with linked lists or so

    Yes, that is a possible solution.

  7. #7
    Registered User
    Join Date
    Mar 2002
    Posts
    9
    you mean we need to simulate the "Math co-processor". Thanks Shiro.

    But i require some infor on how to perform floating point operations. I figured it out that, there are some functions in C which will split the interger part and real part and load it into different numbers or string.

    I need to know more about floating point calculations. Thanks for all your help.

  8. #8
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    There's much info available on floating point arithmetic. For example at:

    http://www.serc.iisc.ernet.in/~ghoshal/story754.html

    >Write a program in 'C' language to add very large floating-point
    >numbers

    But if you only need to add, then that information is not necessary. You can do it just the same way you would do on paper. Just adding the digits and keep a carry in mind.

    Code:
            3 -> . -> 4 -> 4 -> 5
    +
    
    5 -> 3 -> . -> 7
    
    =
    
    5 -> 7 -> . -> 1 -> 4 -> 5
    Take care of the position of the point in the number.

    A quite easy but memory-inefficient way is padding, so that you get numbers of same length. So 3.445 would become 03.445 and 53.7 would become 53.700, then adding would be:

    03.445
    53.700 +

  9. #9
    Unregistered
    Guest

    Wink

    Dont know whether you have simple used the float data type. If this is the case try double (double precision floating point) or long double (extended precision floating point number). Oh yeah good luck! ;-)

  10. #10
    Unregistered
    Guest
    you can use one dimentional arrays with gets to read the number. then substruct from every element of the array the number 48. and you are ok.

  11. #11
    ....
    Join Date
    Aug 2001
    Location
    Groningen (NL)
    Posts
    2,380
    >Dont know whether you have simple used the float data type. If
    >this is the case try double (double precision floating point) or
    >long double (extended precision floating point number). Oh
    >yeah good luck! ;-)

    For very large numbers or numbers with very large precision, C doesn't have standard datatypes for it. That's why this thread was started.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Switch statement
    By BSmith4740 in forum C Programming
    Replies: 29
    Last Post: 02-28-2008, 08:28 PM
  2. Float Function Issues
    By GCNDoug in forum C++ Programming
    Replies: 5
    Last Post: 10-29-2007, 03:25 PM
  3. Need help with program
    By HAssan in forum C Programming
    Replies: 8
    Last Post: 06-10-2007, 08:05 PM
  4. problems storing values in varibles
    By stodd04 in forum C Programming
    Replies: 7
    Last Post: 02-08-2005, 11:56 AM
  5. error in program????
    By SpEkTrE in forum C Programming
    Replies: 5
    Last Post: 11-24-2003, 06:16 PM