Solved

How to deal with big integer class?

Posted on 2003-12-06
3
792 Views
Last Modified: 2010-04-17
/* Sqrt.java    11/12/03  
  it squares each previous squared result*/
import java.text.*;
import java.math.*;
import java.math.BigInteger;
public class Sqrt{
  public static void main(String[] args){
            long[] square = new  long[10];
            int ct;
            square[0]= 2*2;
           for(ct = 1; ct < 10; ct++)
           square[ct] = (long)Math.pow(square[ct-1], 2);
         for(int ct1 = 0; ct1 < 10; ct1++)  
         System.out.println(square[ct1]);
         }
      }
---------------------------------------------------------------------------------
Output:
4
16
256
65536
4294967296
9223372036854775807 (its actual result should be:18446744073709551616
9223372036854775807 (actual:3.4028236692093846346337460743177e+38)
9223372036854775807(actual:1.1579208923731619542357098500866e+77)
9223372036854775807(actual:1.3407807929942597099574024998193e+154)
9223372036854775807(actual:1.7976931348623159077293051907852e+308)
 
 Although I declared the data type as Long, it doesn`t output the right results since they`re out of the range that Long can handle.What kind of data type can handle those sort of humongous numbers?


0
Comment
Question by:edeita2
[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
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

Accepted Solution

by:
dbrunton earned 125 total points
ID: 9889854
0
 

Author Comment

by:edeita2
ID: 9890388
new output:
4.0
16.0
256.0
65536.0
4.294967296E9
1.8446744073709552E19
3.4028236692093846E38
1.157920892373162E77
1.3407807929942597E154
Infinity
 suggestion appreciated
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 9890425
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sp_configure 'external scripts enabled', 1; 7 157
BATCH to EXE Converter 2 99
ASP.NET, Globalization, language indexes, translation, conversion. 2 71
JVM error from eclipse 1 27
This is an explanation of a simple data model to help parse a JSON feed
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question