QLJ
asked on
integer number too large
Hi,
I tried to do this: private static long prime=5095271039;
why is this so? I thgt long gives value to 64bits? This value is obtained from BigInteger.
i want to work with the numbers arithmetically, some int, some BigInteger. DO I need to convert all of them to the same type?
I tried to do this: private static long prime=5095271039;
why is this so? I thgt long gives value to 64bits? This value is obtained from BigInteger.
i want to work with the numbers arithmetically, some int, some BigInteger. DO I need to convert all of them to the same type?
You must use the methods of BigInteger for calcs
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
> DO I need to convert all of them to the same type?
I am afraid you will be needed to do, yes.
Regards
I am afraid you will be needed to do, yes.
Regards
>>some BigInteger
If you have some that are BigInteger, then presumably there's a good reason (they're big), so if they *are* too big for long or int, then you must use BigInteger
If you have some that are BigInteger, then presumably there's a good reason (they're big), so if they *are* too big for long or int, then you must use BigInteger
It is best to make all datatypes the largest datatype needed. Kind of a pain, but it avoid a lot of problems that can result from the JVM overflowing calcluations, then converting the result to the larger type. This doesn't throw any warnings or exceptions, you just get screwy results.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.