Link to home
Start Free TrialLog in
Avatar of QLJ
QLJFlag for Afghanistan

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?
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

You must use the methods of BigInteger for calcs
SOLUTION
Avatar of girionis
girionis
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
> DO I need to convert all of them to the same type?

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
Avatar of bvanderveen
bvanderveen

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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial