Results 1 to 7 of 7
- 05-03-2009, 06:28 AM #1
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
- 05-03-2009, 07:07 AM #2
21! = 51090942171709440000.
what is the max value for long?
You need to use java.math.BigIntegerUSE CODE TAGS--> [CODE]...[/CODE]
Get NotePad++ (free)
- 05-03-2009, 07:12 AM #3
Moderator
- Join Date
- Feb 2009
- Location
- New Zealand
- Posts
- 4,537
- Rep Power
- 11
Java Code:21! = 51090942171709440000 Long.MAX_VALUE = 9223372036854775807
As you yourself say, it's overflowing. Try a more appropriate data type like BigInteger. Or, depending on the accuracy required, an approximation like Stirling's formula.why is this happening and how to solve it.
- 05-04-2009, 04:41 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
A bit more explanation.
I'll just compare this with int and BigInteger. If you are working on with int, after the 12 int produce a garbage. Actually long makes it to 20. Basically throws all the bits out of the range, 32bits for int and 64bits for long. BigInteger also have a limit, which is only on the limit of memory you have.
- 05-04-2009, 06:48 PM #5
Member
- Join Date
- Apr 2009
- Posts
- 4
- Rep Power
- 0
Got the Solution
I try using BigInteger and it works. It works fine for last numbers like 1000!. thanks for every one who try to help. Specially to Eranga. Thank you.
- 05-05-2009, 05:07 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's pleasure to help you lol. :)
So you've solved the problem, please mark the thread solved. You can fin the option on the 'Thread Tools' on top menu of the first post in this thread.
Good luck!
- 05-05-2009, 05:07 PM #7
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
It's pleasure to help you lol. :)
So you've solved the problem, please mark the thread solved. You can fin the option on the 'Thread Tools' on top menu of the first post in this thread.
Good luck!
Similar Threads
-
Graphics2D: stack overflow error
By rosh72851 in forum New To JavaReplies: 11Last Post: 10-15-2008, 09:01 PM -
calculate fft
By ram.west in forum Advanced JavaReplies: 2Last Post: 08-27-2008, 03:05 AM -
Calculate Average
By sthack99 in forum New To JavaReplies: 4Last Post: 06-13-2008, 11:09 AM -
Calculate Tax in java
By toby in forum New To JavaReplies: 2Last Post: 07-30-2007, 09:03 AM -
Calculate what e1 and e2 should be
By Legoland in forum New To JavaReplies: 11Last Post: 07-02-2007, 06:01 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks