Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Storing Big numbers in Java

  • 22-01-2006 01: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, Registered Users 2 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, Registered Users 2 Posts: 4,003 ✭✭✭rsynnott


    BigInteger is arbitrary-precision.


Advertisement