2

I wrote a pretty big program with many methods that use a variable as integer. Is there a way to change it fast to something else? Note that some methods use div and mod on that integer, so trying to change it into Arraylist would mean changing pretty much a lot of code.

I discovered too late that int is not enough to store the numbers that I need(coefficients of polynomials, that is; I though I was going to work with small ones, but ended up needing ones of bigger length than 9).

3
  • 3
    How about .. long? If you need really large number you'll need BigInteger or to change how the values are represented. Mar 24, 2014 at 20:49
  • No, I don't believe there is any quick and easy way to change it to a different type everywhere. Mar 24, 2014 at 20:51
  • Going to try with long. Did already think about BigDecimal, but that means changing a lot, too. Mar 24, 2014 at 20:51

2 Answers 2

5

You can use long, which will give you twice as many bits. If that's not big enough, you can move to BigInteger, which will give you as many as you want, however you won't be able to user operators (like div and mod) directly.

EDIT: The maximum value of a long is 9223372036854775807 (which is 2^63-1)

0

long would probably be what you want to replace them with. If you really do want to replace all instances of int you could probably do something with grep to replace all of them. If you're using Eclipse you could just follow the instructions here.

If not and you're still on a Unix-like system you could use something like grep -rl int <project-directory>/ | xargs sed -i 's/int/long/g'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.