• Post Reply Bookmark Topic Watch Topic
  • New Topic

Dealing with integers bigger than 9223372036854775807  RSS feed

 
Grant Shannon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey all,

I'm writing a small application that is determining probabilities and in the process is utilizing factorials. Thus, as soon it encounters a situation where it needs to calculate 21! or more - i have a problem.

long is no longer cutting the mustard! I had thought that BigLong or BigInteger might be the answer, but having just glanced at them they seem to be more about precision than a simple increase in the size of the value they represent.

I'm positive there is an answer to my problem, I'm just hoping its a simple solution. Any help would be wonderful.
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Grant,

I had no problem writing a factorial method usint BigInteger that easily works generates factorials of 21 and 22 and above.

What have you tried with BigInteger that didn't work.
 
Grant Shannon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to be honest - i haven't tried anything with BigInteger yet.
I looked at it in the API after encountering the helpful looking class name, but it didn't seem to suggest that it could deal with integers larger than 9223372036854775807 explicity.
However, now that you say it can, i will happily go and experiment.

Thanks.
 
Grant Shannon
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a bunch Steve - BigInteger worked a treat
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!