Solved

How to deal with big integer class?

Posted on 2003-12-06
3
751 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
  • 2
3 Comments
 
LVL 47

Accepted Solution

by:
dbrunton earned 125 total points
Comment Utility
0
 

Author Comment

by:edeita2
Comment Utility
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 47

Expert Comment

by:dbrunton
Comment Utility
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Report events not being triggered 8 98
Problem to adjust sheet 1 81
thread-safe code in c++ 2 69
strCount chalenge 3 50
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
This is about my first experience with programming Arduino.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

771 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now