Recursive factorial method returning some negative numbers

社会主义新天地 提交于 2019-12-01 17:50:16

You are overflowing the long. You need to think of it in terms of the binary number that contains the long value. As soon as you add 1 to the maximum positive value that the long can contain, it rolls to the negative minimum.

You might want to read this for a full understanding. http://en.wikipedia.org/wiki/Two%27s_complement

In Java you can use BigInteger for bigger values http://docs.oracle.com/javase/1.4.2/docs/api/java/math/BigInteger.html

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!