Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# integer number too large

Posted on 2004-08-26
Medium Priority
515 Views
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?
0
Question by:QLJ
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 86

Expert Comment

ID: 11904294
You must use the methods of BigInteger for calcs
0

LVL 35

Assisted Solution

girionis earned 80 total points
ID: 11904301
If you have an int you should declare it as an int, otherwise declar its type. Try this:

private static long prime=5095271039L;

Regards
0

LVL 35

Expert Comment

ID: 11904310
> DO I need to convert all of them to the same type?

I am afraid you will be needed to do, yes.

Regards
0

LVL 86

Expert Comment

ID: 11904321
>>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
0

LVL 7

Expert Comment

ID: 11905830
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.
0

LVL 92

Accepted Solution

objects earned 120 total points
ID: 11907425
> DO I need to convert all of them to the same type?

Not at all, you just need to ensure that you cast appropriately.
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different dâ€¦
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
The viewer will learn how to implement Singleton Design Pattern in Java.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
###### Suggested Courses
Course of the Month10 days, 2 hours left to enroll