BigDouble Class

Step 1: problem domain

In this section, we want to develop a class that can support big double numbers and operations among them.

For example we want to calculate 100!/2100  up to 100 decimal places and save it in an object of BigDouble and finally show the results.

 This class is so similar to BigInt, but the difference is decimal places.

Step 2: Public Interface

2-1- Constructor Methods

public BigDouble();   // set to 0.0
public BigDouble(double x);   
public BigDouble(long x);   
public BigDouble(String x);   
//to support:  BigDouble x=new BigDouble("-233523523503452305235030252.00023424234234456734535325674534"); 

public BigDouble(BigDouble x);   
public BigDouble(BigInt x);

2-2- Setter Methods

public void Set(String number);
public void Set(long number);
public void Set(double number);
public void Set(BigInt number);
public void Set(BigDouble number);
public void Set(int index, char digit);
public void Set(int index, byte digit);

2-3- Getter Methods

public byte[] getArray1();       // to get Integer part of number
public byte[] getArray2();       // to get Decimal part of number
public byte digitAt1(int index); // in Integer part
public byte digitAt2(int index); // in Decimal part
public int getSign();
public int Length();       
public int Length1();            // to get length of Integer part of number
public int Length2();            // to get length of Decimal part of number

public long getLastOperationTime();
// by this method, users can get last operation time consuming

2-4- Functionalities of class (Methods)

// x.setSum(a,b);  instead of   x=a+b;
public void setSum(BigDouble a, BigDouble b);

// x.setMinus(a,b);  instead of   x=a-b;
public void setMinus(BigDouble a, BigDouble b);

// x.setMultiple(a,b);  instead of   x=a*b;
public void setMultiple(BigDouble a, BigDouble b);

// x.setDiv(a,b);  instead of   x=a/b;
public void setDiv(BigDouble a, BigDouble b);

// cast to BigInt, delete decimal digits
public BigInt toBigInt(); 

2-5- Standard Library Methods overloading (such as toString, equals,…)

public String toString();
public int compareTo(BigDouble a);
public boolean equals(Object anObject);
public int hashCode();
public BigDouble clone();


Step 3: private variables

Private variables of this class may be implemented two ways:

1- use two Strings S1, S2 and a variable to sign.

2- use an array of byte and length of it and another variable to index of decimal place.

in each method we need a variable to keep the latest operation time.

Step 4: implementing main classes

Students work !

Step 5: useful application

BigDouble CALC projects are applications of this class.