Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
dipsywong98 committed Nov 12, 2017
1 parent 6cf8f38 commit 68684c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 25 deletions.
Binary file removed report.docx
Binary file not shown.
38 changes: 15 additions & 23 deletions report.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,19 @@ remove all nodes in the link list, construct new link list by copying the value

##### d. `a / b`:

1. if b equals to 0, throw division by zero error

2. remove dot of absolute value of a and b, namely `a'` and `b'`.

3. calculate the quota for decimal points in the quotient, which is max of precision of a and b +1 (for rounding)

4. Evaluate max_d, which is the maximum number of zero can be appended to b' to make it just smaller than a'

5. begin the recurrence relation:

1. a' > b'
​ no more quota $=>$ end with NULL
​ have quota
​ do a' * 10 /b and drop one quota, and if it is the first time to use quota, append .

2. else

​ evaluate number of times a' can be subtracted by ${b'}*10^{max_d}$ and let it be d.

​ returned number is d coming with resultant digits of $(a'-d*{b'}*10^{max_d})/b'$ which this / sign
​ is calling the recurrence function with max_d decrease by 1.
1. preprocess:
1. if b equals to 0, throw division by zero error
2. let absolute of `a` and `b` be `a'` and `b'` respectively.
3. calculate the resultant precision as 1+ max of a's precision and b's precision.
4. make a' to be $a' * 10^{precision}$ so that the quotient will have extra digits (calculating the decimals).
2. recursion:
1. if a<b terminate 2. with 0
2. else
1. calculate the more significant quotient, p, by calling a/(b*10)
2. calculate the remainder by the more significant quotient, $r=a' - b*p*10$
3. let the quotient generated by this recursion level is $q$, while $r>=b'$, subtract $b'$ from $r$ and $q$ increment by 1.
4. finally leave 2. with the combined quotient of this recursion level and previous levels, $q+p*10$
3. add back the sign and decimal point to the rounded result and return.

##### e. `a ^ b `:

Expand All @@ -124,8 +116,8 @@ remove all nodes in the link list, construct new link list by copying the value
3. if b equals 1, result is a
4. if b equals 2, result is a*a
5. else
1. turn $b$ to a bit-string, set result as 1.
2. for each digit $b_i$ in $b$, if $b_i$ is 1,result multiply by ${a}^{2^i}$
1. turn $b$ to a bit-string, set `result` as 1.
2. for each digit $b_i$ in $b$, if $b_i$ is 1, `result` multiply by ${a}^{2^i}$
3. return result

##### f. increment and decrement
Expand Down
Binary file added report.pdf
Binary file not shown.
2 changes: 0 additions & 2 deletions task1/bigDecimal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,6 @@ BigDecimal BigDecimal::operator/(const BigDecimal &bi) const{
for(int i=0; i<quota; i++){
a=a*10;
}

// cout<<"quota "<<quota<<endl;

BigDecimal result = div(a,b);
result.linkList->data = (sign()==bi.sign()?'+':'-');
Expand Down

0 comments on commit 68684c9

Please sign in to comment.