Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Storing Big numbers in Java

Options
  • 22-01-2006 1:05am
    #1
    Closed Accounts Posts: 201 ✭✭


    I have a problem trying to store a very large number in java im multiplying numbers together and then multiplying the next number onto the multiplication of the previous two as in

    sum=1*2000
    sum=2000*3000
    sum=6000*4000

    etc.

    the sum reaches a point after awhile where it just becomes infinity in the output its around x.xxE200 or somthing around that exponent im wondering does anyone know how I may get round this problem.Is there a BigDouble variable I could use or something?

    Cheers


Comments

  • Closed Accounts Posts: 4,943 ✭✭✭Mutant_Fruit


    well... you could write a function that "multiplies" using strings. Theres no length on a string, so you could hold as many digits as you want. But you'd need to write a few functions in order to handle 'multiplying' the string by a number. Should be doable though.


  • Registered Users Posts: 1,272 ✭✭✭i_am_dogboy


    There's a BigInteger class in java.math, have a look at the javadoc and see if it's big enough for what you need.


  • Closed Accounts Posts: 888 ✭✭✭themole


    if the big integer class mentioned is not big enough,

    try looking for a GNU Multiple Precision class. i ued this before in PHP, dunno if there is a java version, give it a search.

    but the cool thing about it is that it does arbitrary precision mathematics, ie the only limit to the size of the numbers is the computers memory/hdd size


  • Registered Users Posts: 4,003 ✭✭✭rsynnott


    BigInteger is arbitrary-precision.


Advertisement