|
<html><head><title>dlib C++ Library - bigint_kernel_2.cpp</title></head><body bgcolor='white'><pre> |
|
<font color='#009900'>// Copyright (C) 2003 Davis E. King ([email protected]) |
|
</font><font color='#009900'>// License: Boost Software License See LICENSE.txt for the full license. |
|
</font><font color='#0000FF'>#ifndef</font> DLIB_BIGINT_KERNEL_2_CPp_ |
|
<font color='#0000FF'>#define</font> DLIB_BIGINT_KERNEL_2_CPp_ |
|
<font color='#0000FF'>#include</font> "<a style='text-decoration:none' href='bigint_kernel_2.h.html'>bigint_kernel_2.h</a>" |
|
|
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>iostream<font color='#5555FF'>></font> |
|
<font color='#0000FF'>#include</font> <font color='#5555FF'><</font>cmath<font color='#5555FF'>></font> |
|
|
|
<font color='#0000FF'>namespace</font> dlib |
|
<b>{</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> <font color='#009900'>// member/friend function definitions |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2:: |
|
<b><a name='bigint_kernel_2'></a>bigint_kernel_2</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> : |
|
slack<font face='Lucida Console'>(</font><font color='#979000'>25</font><font face='Lucida Console'>)</font>, |
|
data<font face='Lucida Console'>(</font><font color='#0000FF'>new</font> data_record<font face='Lucida Console'>(</font>slack<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b><b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2:: |
|
<b><a name='bigint_kernel_2'></a>bigint_kernel_2</b> <font face='Lucida Console'>(</font> |
|
uint32 value |
|
<font face='Lucida Console'>)</font> : |
|
slack<font face='Lucida Console'>(</font><font color='#979000'>25</font><font face='Lucida Console'>)</font>, |
|
data<font face='Lucida Console'>(</font><font color='#0000FF'>new</font> data_record<font face='Lucida Console'>(</font>slack<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>value<font color='#5555FF'>&</font><font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>value<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font><font color='#5555FF'>&</font><font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>2</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2:: |
|
<b><a name='bigint_kernel_2'></a>bigint_kernel_2</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> item |
|
<font face='Lucida Console'>)</font> : |
|
slack<font face='Lucida Console'>(</font><font color='#979000'>25</font><font face='Lucida Console'>)</font>, |
|
data<font face='Lucida Console'>(</font>item.data<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2:: |
|
~<b><a name='bigint_kernel_2'></a>bigint_kernel_2</b> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>delete</font> data; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font> <font face='Lucida Console'>(</font> |
|
std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used,data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font> <font color='#5555FF'>+</font> slack |
|
<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>long_add</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to our data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used,rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>long_add</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// if data is not big enough for the result |
|
</font> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>size <font color='#5555FF'><</font><font color='#5555FF'>=</font> std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used,rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>max</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used,rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>long_add</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> data; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// there is enough size and no references |
|
</font> <font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>long_add</font><font face='Lucida Console'>(</font>data,rhs.data,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>-</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font> <font face='Lucida Console'>(</font> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> slack |
|
<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>long_sub</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>long_sub</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>long_sub</font><font face='Lucida Console'>(</font>data,rhs.data,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>*</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font> <font face='Lucida Console'>(</font> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> slack |
|
<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>long_mul</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// create a data_record to store the result of the multiplication in |
|
</font> data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>long_mul</font><font face='Lucida Console'>(</font>data,rhs.data,temp<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// if there are other references to data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'>delete</font> data; |
|
<b>}</b> |
|
data <font color='#5555FF'>=</font> temp; |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>/</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data_record<font color='#5555FF'>*</font> remainder; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
remainder <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> temp; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#BB00BB'>long_div</font><font face='Lucida Console'>(</font>data,rhs.data,temp,remainder<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> remainder; |
|
|
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
|
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data_record<font color='#5555FF'>*</font> remainder; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
remainder <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> temp; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#BB00BB'>long_div</font><font face='Lucida Console'>(</font>data,rhs.data,temp,remainder<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// check if there are other references to data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#009900'>// if there are no references to data then it must be deleted |
|
</font> <font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'>delete</font> data; |
|
<b>}</b> |
|
data <font color='#5555FF'>=</font> temp; |
|
<font color='#0000FF'>delete</font> remainder; |
|
|
|
|
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>%</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data_record<font color='#5555FF'>*</font> remainder; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
remainder <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> temp; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#BB00BB'>long_div</font><font face='Lucida Console'>(</font>data,rhs.data,temp,remainder<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> temp; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>remainder,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>%</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data_record<font color='#5555FF'>*</font> remainder; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
remainder <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> temp; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#BB00BB'>long_div</font><font face='Lucida Console'>(</font>data,rhs.data,temp,remainder<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// check if there are other references to data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#009900'>// if there are no references to data then it must be deleted |
|
</font> <font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#0000FF'>delete</font> data; |
|
<b>}</b> |
|
data <font color='#5555FF'>=</font> remainder; |
|
<font color='#0000FF'>delete</font> temp; |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b> <font color='#5555FF'><</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>is_less_than</font><font face='Lucida Console'>(</font>data,rhs.data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>is_equal_to</font><font face='Lucida Console'>(</font>data,rhs.data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#0000FF'>this</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#5555FF'>&</font>rhs<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
|
|
<font color='#009900'>// if we have the only reference to our data then delete it |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>delete</font> data; |
|
data <font color='#5555FF'>=</font> rhs.data; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
data <font color='#5555FF'>=</font> rhs.data; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
std::ostream<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'><</font><font color='#5555FF'><</font> <font face='Lucida Console'>(</font> |
|
std::ostream<font color='#5555FF'>&</font> out_, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
std::ostream <font color='#BB00BB'>out</font><font face='Lucida Console'>(</font>out_.<font color='#BB00BB'>rdbuf</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
|
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>rhs.data,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
|
|
|
|
|
|
<font color='#009900'>// get a char array big enough to hold the number in ascii format |
|
</font> <font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
str <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#0000FF'><u>char</u></font>[<font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>5</font><font color='#5555FF'>+</font><font color='#979000'>10</font>]; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> temp; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#0000FF'><u>char</u></font><font color='#5555FF'>*</font> str_start <font color='#5555FF'>=</font> str; |
|
str <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>5</font><font color='#5555FF'>+</font><font color='#979000'>9</font>; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> <font color='#979000'>0</font>; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
|
|
|
|
uint16 remainder; |
|
rhs.<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>10000</font>,temp,remainder<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// pull the digits out of remainder |
|
</font> <font color='#0000FF'><u>char</u></font> a <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> b <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> c <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> d <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
|
|
|
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> a; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> b; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> c; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> d; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
|
|
|
|
<font color='#009900'>// keep looping until temp represents zero |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
rhs.<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>10000</font>,temp,remainder<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// pull the digits out of remainder |
|
</font> <font color='#0000FF'><u>char</u></font> a <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> b <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> c <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
<font color='#0000FF'><u>char</u></font> d <font color='#5555FF'>=</font> remainder <font color='#5555FF'>%</font> <font color='#979000'>10</font> <font color='#5555FF'>+</font> '<font color='#FF0000'>0</font>'; |
|
remainder <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
|
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> a; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> b; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> c; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<font color='#5555FF'>*</font>str <font color='#5555FF'>=</font> d; <font color='#5555FF'>-</font><font color='#5555FF'>-</font>str; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// throw away and extra leading zeros |
|
</font> <font color='#5555FF'>+</font><font color='#5555FF'>+</font>str; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>str <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>str; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>str <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>str; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>str <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>'<font face='Lucida Console'>)</font> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>str; |
|
|
|
|
|
|
|
|
|
out <font color='#5555FF'><</font><font color='#5555FF'><</font> str; |
|
<font color='#0000FF'>delete</font> [] str_start; |
|
<font color='#0000FF'>delete</font> temp; |
|
<font color='#0000FF'>return</font> out_; |
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
std::istream<font color='#5555FF'>&</font> <b><a name='operator'></a>operator</b><font color='#5555FF'>></font><font color='#5555FF'>></font> <font face='Lucida Console'>(</font> |
|
std::istream<font color='#5555FF'>&</font> in_, |
|
bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
std::istream <font color='#BB00BB'>in</font><font face='Lucida Console'>(</font>in_.<font color='#BB00BB'>rdbuf</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// ignore any leading whitespaces |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'> </font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\t</font>' <font color='#5555FF'>|</font><font color='#5555FF'>|</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> '<font color='#FF0000'>\n</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// if the first digit is not an integer then this is an error |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font> <font color='#5555FF'>!</font><font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>' <font color='#5555FF'>&</font><font color='#5555FF'>&</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> '<font color='#FF0000'>9</font>'<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
in_.<font color='#BB00BB'>clear</font><font face='Lucida Console'>(</font>std::ios::failbit<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> in_; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'><u>int</u></font> num_read; |
|
bigint_kernel_2 temp; |
|
<font color='#0000FF'>do</font> |
|
<b>{</b> |
|
|
|
<font color='#009900'>// try to get 4 chars from in |
|
</font> num_read <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'><u>char</u></font> a <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'><u>char</u></font> b <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'><u>char</u></font> c <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'><u>char</u></font> d <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>' <font color='#5555FF'>&</font><font color='#5555FF'>&</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> '<font color='#FF0000'>9</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num_read <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
a <font color='#5555FF'>=</font> in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>' <font color='#5555FF'>&</font><font color='#5555FF'>&</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> '<font color='#FF0000'>9</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num_read <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
b <font color='#5555FF'>=</font> in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>' <font color='#5555FF'>&</font><font color='#5555FF'>&</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> '<font color='#FF0000'>9</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num_read <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
c <font color='#5555FF'>=</font> in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>=</font> '<font color='#FF0000'>0</font>' <font color='#5555FF'>&</font><font color='#5555FF'>&</font> in.<font color='#BB00BB'>peek</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'>=</font> '<font color='#FF0000'>9</font>'<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num_read <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
d <font color='#5555FF'>=</font> in.<font color='#BB00BB'>get</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// merge the for digits into an uint16 |
|
</font> uint16 num <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>a <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num <font color='#5555FF'>=</font> a <font color='#5555FF'>-</font> '<font color='#FF0000'>0</font>'; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>b <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
num <font color='#5555FF'>+</font><font color='#5555FF'>=</font> b <font color='#5555FF'>-</font> '<font color='#FF0000'>0</font>'; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>c <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
num <font color='#5555FF'>+</font><font color='#5555FF'>=</font> c <font color='#5555FF'>-</font> '<font color='#FF0000'>0</font>'; |
|
<b>}</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>d <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
num <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>10</font>; |
|
num <font color='#5555FF'>+</font><font color='#5555FF'>=</font> d <font color='#5555FF'>-</font> '<font color='#FF0000'>0</font>'; |
|
<b>}</b> |
|
|
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num_read <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// shift the digits in temp left by the number of new digits we just read |
|
</font> temp <font color='#5555FF'>*</font><font color='#5555FF'>=</font> num_read; |
|
<font color='#009900'>// add in new digits |
|
</font> temp <font color='#5555FF'>+</font><font color='#5555FF'>=</font> num; |
|
<b>}</b> |
|
|
|
<b>}</b> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>num_read <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>10000</font><font face='Lucida Console'>)</font>; |
|
|
|
|
|
rhs <font color='#5555FF'>=</font> temp; |
|
<font color='#0000FF'>return</font> in_; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>rhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
rhs.<font color='#BB00BB'>short_add</font><font face='Lucida Console'>(</font>rhs.data,lhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>lhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
lhs.<font color='#BB00BB'>short_add</font><font face='Lucida Console'>(</font>lhs.data,rhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>short_add</font><font face='Lucida Console'>(</font>data,rhs,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// or if we need to enlarge data then do so |
|
</font> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>size<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>short_add</font><font face='Lucida Console'>(</font>data,rhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> data; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// or if there is plenty of space and no references |
|
</font> <font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>short_add</font><font face='Lucida Console'>(</font>data,rhs,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>-</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>rhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> lhs <font color='#5555FF'>-</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>-</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>lhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
lhs.<font color='#BB00BB'>short_sub</font><font face='Lucida Console'>(</font>lhs.data,rhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>short_sub</font><font face='Lucida Console'>(</font>data,rhs,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>short_sub</font><font face='Lucida Console'>(</font>data,rhs,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>*</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>rhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
rhs.<font color='#BB00BB'>short_mul</font><font face='Lucida Console'>(</font>rhs.data,lhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>*</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>lhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
lhs.<font color='#BB00BB'>short_mul</font><font face='Lucida Console'>(</font>lhs.data,rhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>short_mul</font><font face='Lucida Console'>(</font>data,rhs,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// or if we need to enlarge data |
|
</font> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>size<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>short_mul</font><font face='Lucida Console'>(</font>data,rhs,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> data; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>short_mul</font><font face='Lucida Console'>(</font>data,rhs,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>/</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>rhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// if rhs might not be bigger than lhs |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> lhs<font color='#5555FF'>/</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>/</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font> |
|
<font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>lhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
uint16 remainder; |
|
lhs.<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>lhs.data,rhs,temp,remainder<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
uint16 remainder; |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>data,rhs,temp,remainder<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>data,rhs,data,remainder<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>%</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
<font color='#009900'>// temp is zero by default |
|
</font> bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>rhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if rhs is just an uint16 inside then perform the modulus |
|
</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> lhs <font color='#5555FF'>%</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#009900'>// if rhs is bigger than lhs then the answer is lhs |
|
</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> lhs; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 <b><a name='operator'></a>operator</b><font color='#5555FF'>%</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>typedef</font> bigint_kernel_2 bigint; |
|
bigint::data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> bigint::<font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>lhs.slack<font face='Lucida Console'>)</font>; |
|
|
|
uint16 remainder; |
|
|
|
lhs.<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>lhs.data,rhs,temp,remainder<font face='Lucida Console'>)</font>; |
|
temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> remainder; |
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>%</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
uint16 remainder; |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>data,rhs,temp,remainder<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>short_div</font><font face='Lucida Console'>(</font>data,rhs,data,remainder<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> remainder; |
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'><</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>></font> <font color='#979000'>1</font> <font color='#5555FF'>|</font><font color='#5555FF'>|</font> lhs <font color='#5555FF'><</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'><</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'><</font> rhs<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> lhs, |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>lhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> rhs<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> <b><a name='operator'></a>operator</b> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 lhs, |
|
<font color='#0000FF'>const</font> bigint_kernel_2<font color='#5555FF'>&</font> rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>rhs.data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> lhs<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>=</font> <font face='Lucida Console'>(</font> |
|
uint16 rhs |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// check if there are other references to our data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>try</font> <b>{</b> |
|
data <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>slack<font face='Lucida Console'>)</font>; |
|
<b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>+</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; <font color='#0000FF'>throw</font>; <b>}</b> |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> rhs; |
|
|
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data then make a copy of it |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>increment</font><font face='Lucida Console'>(</font>data,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#009900'>// or if we need to enlarge data then do so |
|
</font> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>size<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>increment</font><font face='Lucida Console'>(</font>data,temp<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>delete</font> data; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>increment</font><font face='Lucida Console'>(</font>data,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>+</font><font color='#5555FF'>+</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>int</u></font> |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp; <font color='#009900'>// this is the copy of temp we will return in the end |
|
</font> |
|
data_record<font color='#5555FF'>*</font> temp2 <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>increment</font><font face='Lucida Console'>(</font>data,temp2<font face='Lucida Console'>)</font>; |
|
|
|
temp <font color='#5555FF'>=</font> data; |
|
data <font color='#5555FF'>=</font> temp2; |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
bigint_kernel_2<font color='#5555FF'>&</font> bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font face='Lucida Console'>(</font> |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if there are other references to this data |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
data<font color='#5555FF'>-</font><font color='#5555FF'>></font>references <font color='#5555FF'>-</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#BB00BB'>decrement</font><font face='Lucida Console'>(</font>data,temp<font face='Lucida Console'>)</font>; |
|
data <font color='#5555FF'>=</font> temp; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>decrement</font><font face='Lucida Console'>(</font>data,data<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>return</font> <font color='#5555FF'>*</font><font color='#0000FF'>this</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'>const</font> bigint_kernel_2 bigint_kernel_2:: |
|
<b><a name='operator'></a>operator</b><font color='#5555FF'>-</font><font color='#5555FF'>-</font> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'><u>int</u></font> |
|
<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
data_record<font color='#5555FF'>*</font> temp; <font color='#009900'>// this is the copy of temp we will return in the end |
|
</font> |
|
data_record<font color='#5555FF'>*</font> temp2 <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> <font color='#BB00BB'>data_record</font><font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>decrement</font><font face='Lucida Console'>(</font>data,temp2<font face='Lucida Console'>)</font>; |
|
|
|
temp <font color='#5555FF'>=</font> data; |
|
data <font color='#5555FF'>=</font> temp2; |
|
|
|
<font color='#0000FF'>return</font> <font color='#BB00BB'>bigint_kernel_2</font><font face='Lucida Console'>(</font>temp,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> <font color='#009900'>// private member function definitions |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font><font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='short_add'></a>short_add</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
uint16 value, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#009900'>// put value into the carry part of temp |
|
</font> uint32 temp <font color='#5555FF'>=</font> value; |
|
temp <font color='#5555FF'><</font><font color='#5555FF'><</font><font color='#5555FF'>=</font> <font color='#979000'>16</font>; |
|
|
|
|
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> number <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; <font color='#009900'>// one past the end of number |
|
</font> uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>number <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// add *number and the current carry |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// if there is a final carry |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<font color='#009900'>// store the carry in the most significant digit of the result |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='short_sub'></a>short_sub</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
uint16 value, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
|
|
|
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> number <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
|
|
uint32 temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number <font color='#5555FF'>-</font> value; |
|
|
|
<font color='#009900'>// put the low word of temp into *data |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>number <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
|
|
<font color='#009900'>// subtract the carry from *number |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>31</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// if we lost a digit in the subtraction |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>else</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
|
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='short_mul'></a>short_mul</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
uint16 value, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
|
|
uint32 temp <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
|
|
|
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
|
|
|
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font> r <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
|
|
<font color='#009900'>// multiply *data and value and add in the carry |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>uint32<font face='Lucida Console'>)</font>value <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// put the low word of temp into *data |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// if there is a final carry |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<font color='#009900'>// put the final carry into the most significant digit of the result |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
|
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='short_div'></a>short_div</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
uint16 value, |
|
data_record<font color='#5555FF'>*</font> result, |
|
uint16<font color='#5555FF'>&</font> rem |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
|
|
uint16 remainder <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
uint32 temp; |
|
|
|
|
|
|
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> number <font color='#5555FF'>-</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
|
|
|
|
<font color='#009900'>// if we are losing a digit in this division |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>number <font color='#5555FF'><</font> value<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>else</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
|
|
|
|
<font color='#009900'>// perform the actual division |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>number <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
|
|
temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>uint32<font face='Lucida Console'>)</font>remainder<font face='Lucida Console'>)</font><font color='#5555FF'><</font><font color='#5555FF'><</font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>/</font>value<font face='Lucida Console'>)</font>; |
|
remainder <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>%</font>value<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>number; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
<b>}</b> |
|
|
|
rem <font color='#5555FF'>=</font> remainder; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='long_add'></a>long_add</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#009900'>// put value into the carry part of temp |
|
</font> uint32 temp<font color='#5555FF'>=</font><font color='#979000'>0</font>; |
|
|
|
uint16<font color='#5555FF'>*</font> min_num; <font color='#009900'>// the number with the least digits used |
|
</font> uint16<font color='#5555FF'>*</font> max_num; <font color='#009900'>// the number with the most digits used |
|
</font> uint16<font color='#5555FF'>*</font> min_end; <font color='#009900'>// one past the end of min_num |
|
</font> uint16<font color='#5555FF'>*</font> max_end; <font color='#009900'>// one past the end of max_num |
|
</font> uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
|
|
uint32 max_digits_used; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'><</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
max_digits_used <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
min_num <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
max_num <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
min_end <font color='#5555FF'>=</font> min_num <font color='#5555FF'>+</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
max_end <font color='#5555FF'>=</font> max_num <font color='#5555FF'>+</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
max_digits_used <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
min_num <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
max_num <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
min_end <font color='#5555FF'>=</font> min_num <font color='#5555FF'>+</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
max_end <font color='#5555FF'>=</font> max_num <font color='#5555FF'>+</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
|
|
|
|
|
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>min_num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> min_end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// add *min_num, *max_num and the current carry |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>min_num <font color='#5555FF'>+</font> <font color='#5555FF'>*</font>max_num <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>min_num; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>max_num; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>max_num <font color='#5555FF'>!</font><font color='#5555FF'>=</font> max_end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// add *max_num and the current carry |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>max_num <font color='#5555FF'>+</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>max_num; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// check if there was a final carry |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> max_digits_used <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<font color='#009900'>// put the carry into the most significant digit in the result |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>16</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> max_digits_used; |
|
<b>}</b> |
|
|
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='long_sub'></a>long_sub</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
|
|
|
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number1 <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> number2 <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>const</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> number2 <font color='#5555FF'>+</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
|
|
|
|
|
|
uint32 temp <font color='#5555FF'>=</font><font color='#979000'>0</font>; |
|
|
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>number2 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
|
|
<font color='#009900'>// subtract *number2 from *number1 and then subtract any carry |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number1 <font color='#5555FF'>-</font> <font color='#5555FF'>*</font>number2 <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>31</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number1; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number2; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
end <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number <font color='#5555FF'>+</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>number1 <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
|
|
<font color='#009900'>// subtract the carry from *number1 |
|
</font> temp <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>number1 <font color='#5555FF'>-</font> <font face='Lucida Console'>(</font>temp<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>31</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// put the low word of temp into *r |
|
</font> <font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>temp <font color='#5555FF'>&</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>number1; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#009900'>// adjust the number of digits used appropriately |
|
</font> <font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>></font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='long_div'></a>long_div</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs, |
|
data_record<font color='#5555FF'>*</font> result, |
|
data_record<font color='#5555FF'>*</font> remainder |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#009900'>// zero result |
|
</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
|
|
uint16<font color='#5555FF'>*</font> a; |
|
uint16<font color='#5555FF'>*</font> b; |
|
uint16<font color='#5555FF'>*</font> end; |
|
|
|
<font color='#009900'>// copy lhs into remainder |
|
</font> remainder<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
a <font color='#5555FF'>=</font> remainder<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
end <font color='#5555FF'>=</font> a <font color='#5555FF'>+</font> remainder<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
b <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>a <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>a <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>b; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>a; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>b; |
|
<b>}</b> |
|
|
|
|
|
<font color='#009900'>// if rhs is bigger than lhs then result == 0 and remainder == lhs |
|
</font> <font color='#009900'>// so then we can quit right now |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_less_than</font><font face='Lucida Console'>(</font>lhs,rhs<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font>; |
|
<b>}</b> |
|
|
|
|
|
<font color='#009900'>// make a temporary number |
|
</font> data_record <font color='#BB00BB'>temp</font><font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> slack<font face='Lucida Console'>)</font>; |
|
|
|
|
|
<font color='#009900'>// shift rhs left until it is one shift away from being larger than lhs and |
|
</font> <font color='#009900'>// put the number of left shifts necessary into shifts |
|
</font> uint32 shifts; |
|
shifts <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font> <font color='#5555FF'>*</font> <font color='#979000'>16</font>; |
|
|
|
<font color='#BB00BB'>shift_left</font><font face='Lucida Console'>(</font>rhs,<font color='#5555FF'>&</font>temp,shifts<font face='Lucida Console'>)</font>; |
|
|
|
|
|
<font color='#009900'>// while (lhs > temp) |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_less_than</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>temp,lhs<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>shift_left</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>temp,<font color='#5555FF'>&</font>temp,<font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>shifts; |
|
<b>}</b> |
|
<font color='#009900'>// make sure lhs isn't smaller than temp |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#BB00BB'>is_less_than</font><font face='Lucida Console'>(</font>lhs,<font color='#5555FF'>&</font>temp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>shift_right</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>temp,<font color='#5555FF'>&</font>temp<font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>shifts; |
|
<b>}</b> |
|
|
|
|
|
|
|
<font color='#009900'>// we want to execute the loop shifts +1 times |
|
</font> <font color='#5555FF'>+</font><font color='#5555FF'>+</font>shifts; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>shifts <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>shift_left</font><font face='Lucida Console'>(</font>result,result,<font color='#979000'>1</font><font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// if (temp <= remainder) |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>!</font><font color='#BB00BB'>is_less_than</font><font face='Lucida Console'>(</font>remainder,<font color='#5555FF'>&</font>temp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>long_sub</font><font face='Lucida Console'>(</font>remainder,<font color='#5555FF'>&</font>temp,remainder<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// increment result |
|
</font> uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> r <font color='#5555FF'>+</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r<font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// if there was no carry then we are done |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>break</font>; |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
|
|
<font color='#009900'>// if we hit the end of r and there is still a carry then |
|
</font> <font color='#009900'>// the next digit of r is 1 and there is one more digit used |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font>; |
|
<font color='#0000FF'>break</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
<b>}</b> |
|
<font color='#BB00BB'>shift_right</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>temp,<font color='#5555FF'>&</font>temp<font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>shifts; |
|
<b>}</b> |
|
|
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='long_mul'></a>long_mul</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#009900'>// if one of the numbers is small then use this simple but O(n^2) algorithm |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>std::<font color='#BB00BB'>min</font><font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used, rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font> <font color='#5555FF'><</font> <font color='#979000'>10</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// make result be zero |
|
</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
|
|
|
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> aa; |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> bb; |
|
|
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'><</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// make copies of lhs and rhs and give them an appropriate amount of |
|
</font> <font color='#009900'>// extra memory so there won't be any overflows |
|
</font> aa <font color='#5555FF'>=</font> lhs; |
|
bb <font color='#5555FF'>=</font> rhs; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#009900'>// make copies of lhs and rhs and give them an appropriate amount of |
|
</font> <font color='#009900'>// extra memory so there won't be any overflows |
|
</font> aa <font color='#5555FF'>=</font> rhs; |
|
bb <font color='#5555FF'>=</font> lhs; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// copy the larger(approximately) of lhs and rhs into b |
|
</font> data_record <font color='#BB00BB'>b</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>bb,aa<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>+</font>slack<font face='Lucida Console'>)</font>; |
|
|
|
|
|
uint32 shift_value <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
uint16<font color='#5555FF'>*</font> anum <font color='#5555FF'>=</font> aa<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> anum <font color='#5555FF'>+</font> aa<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>anum <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end <font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
uint16 bit <font color='#5555FF'>=</font> <font color='#979000'>0x0001</font>; |
|
|
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>int</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> <font color='#979000'>16</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if the specified bit of a is 1 |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>anum <font color='#5555FF'>&</font> bit<font face='Lucida Console'>)</font> <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#BB00BB'>shift_left</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>b,<font color='#5555FF'>&</font>b,shift_value<font face='Lucida Console'>)</font>; |
|
shift_value <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#BB00BB'>long_add</font><font face='Lucida Console'>(</font><font color='#5555FF'>&</font>b,result,result<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>shift_value; |
|
bit <font color='#5555FF'><</font><font color='#5555FF'><</font><font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>anum; |
|
<b>}</b> |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> <font color='#009900'>// else if both lhs and rhs are large then use the more complex |
|
</font> <font color='#009900'>// O(n*logn) algorithm |
|
</font> <b>{</b> |
|
uint32 size <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#009900'>// make size a power of 2 |
|
</font> <font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>size <font color='#5555FF'><</font> <font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font><font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
size <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// allocate some temporary space so we can do the FFT |
|
</font> ct<font color='#5555FF'>*</font> a <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> ct[size]; |
|
ct<font color='#5555FF'>*</font> b; <font color='#0000FF'>try</font> <b>{</b>b <font color='#5555FF'>=</font> <font color='#0000FF'>new</font> ct[size]; <b>}</b> <font color='#0000FF'>catch</font> <font face='Lucida Console'>(</font>...<font face='Lucida Console'>)</font> <b>{</b> <font color='#0000FF'>delete</font> [] a; <font color='#0000FF'>throw</font>; <b>}</b> |
|
|
|
<font color='#009900'>// load lhs into the a array. We are breaking the input number into |
|
</font> <font color='#009900'>// 8bit chunks for the purpose of using this fft algorithm. The reason |
|
</font> <font color='#009900'>// for this is so that we have smaller numbers coming out of the final |
|
</font> <font color='#009900'>// ifft. This helps avoid overflow. |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>uint32 i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
a[i<font color='#5555FF'>*</font><font color='#979000'>2</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>t<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number[i]<font color='#5555FF'>&</font><font color='#979000'>0xFF</font><font face='Lucida Console'>)</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
a[i<font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>t<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number[i]<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>8</font><font face='Lucida Console'>)</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>uint32 i <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>*</font><font color='#979000'>2</font>; i <font color='#5555FF'><</font> size; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
a[i] <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// load rhs into the b array |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>uint32 i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
b[i<font color='#5555FF'>*</font><font color='#979000'>2</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>t<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number[i]<font color='#5555FF'>&</font><font color='#979000'>0xFF</font><font face='Lucida Console'>)</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
b[i<font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font>] <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font><font face='Lucida Console'>(</font>t<font face='Lucida Console'>)</font><font face='Lucida Console'>(</font>rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number[i]<font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#979000'>8</font><font face='Lucida Console'>)</font>,<font color='#979000'>0</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>uint32 i <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font color='#5555FF'>*</font><font color='#979000'>2</font>; i <font color='#5555FF'><</font> size; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
b[i] <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// perform the forward fft of a and b |
|
</font> <font color='#BB00BB'>fft</font><font face='Lucida Console'>(</font>a,size<font face='Lucida Console'>)</font>; |
|
<font color='#BB00BB'>fft</font><font face='Lucida Console'>(</font>b,size<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>double</u></font> l <font color='#5555FF'>=</font> <font color='#979000'>1.0</font><font color='#5555FF'>/</font>size; |
|
|
|
<font color='#009900'>// do the pointwise multiply of a and b and also apply the scale |
|
</font> <font color='#009900'>// factor in this loop too. |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> size; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
a[i] <font color='#5555FF'>=</font> l<font color='#5555FF'>*</font>a[i]<font color='#5555FF'>*</font>b[i]; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// Now compute the inverse fft of the pointwise multiplication of a and b. |
|
</font> <font color='#009900'>// This is basically the result. We just have to take care of any carries |
|
</font> <font color='#009900'>// that should happen. |
|
</font> <font color='#BB00BB'>ifft</font><font face='Lucida Console'>(</font>a,size<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// loop over the result and propagate any carries that need to take place. |
|
</font> <font color='#009900'>// We will also be moving the resulting numbers into result->number at |
|
</font> <font color='#009900'>// the same time. |
|
</font> uint64 carry <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'><u>int</u></font> zeros <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>const</font> uint32 len <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> i <font color='#5555FF'>=</font> <font color='#979000'>0</font>; i <font color='#5555FF'><</font> len; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>i<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
uint64 num1 <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint64<font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>a[i<font color='#5555FF'>*</font><font color='#979000'>2</font>].<font color='#BB00BB'>real</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>0.5</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
num1 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> carry; |
|
carry <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num1 <font color='#5555FF'>></font> <font color='#979000'>255</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
carry <font color='#5555FF'>=</font> num1 <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>8</font>; |
|
num1 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>num1<font color='#5555FF'>&</font><font color='#979000'>0xFF</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
uint64 num2 <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint64<font color='#5555FF'>></font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>floor</font><font face='Lucida Console'>(</font>a[i<font color='#5555FF'>*</font><font color='#979000'>2</font><font color='#5555FF'>+</font><font color='#979000'>1</font>].<font color='#BB00BB'>real</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font><font color='#5555FF'>+</font><font color='#979000'>0.5</font><font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
num2 <font color='#5555FF'>+</font><font color='#5555FF'>=</font> carry; |
|
carry <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num2 <font color='#5555FF'>></font> <font color='#979000'>255</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
carry <font color='#5555FF'>=</font> num2 <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>8</font>; |
|
num2 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>num2<font color='#5555FF'>&</font><font color='#979000'>0xFF</font><font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// put the new number into its final place |
|
</font> num1 <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>num2<font color='#5555FF'><</font><font color='#5555FF'><</font><font color='#979000'>8</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font> num1; |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number[i] <font color='#5555FF'>=</font> <font color='#0000FF'>static_cast</font><font color='#5555FF'><</font>uint16<font color='#5555FF'>></font><font face='Lucida Console'>(</font>num1<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// keep track of the number of leading zeros |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>num1 <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>zeros; |
|
<font color='#0000FF'>else</font> |
|
zeros <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font><font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used<font face='Lucida Console'>)</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// adjust digits_used so that it reflects the actual number |
|
</font> <font color='#009900'>// of non-zero digits in our representation. |
|
</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font><font color='#5555FF'>=</font> zeros; |
|
|
|
<font color='#009900'>// if the result was zero then adjust the result accordingly |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// make result be zero |
|
</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font>result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// free all the temporary buffers |
|
</font> <font color='#0000FF'>delete</font> [] a; |
|
<font color='#0000FF'>delete</font> [] b; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='shift_left'></a>shift_left</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
data_record<font color='#5555FF'>*</font> result, |
|
uint32 shift_amount |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
uint32 offset <font color='#5555FF'>=</font> shift_amount<font color='#5555FF'>/</font><font color='#979000'>16</font>; |
|
shift_amount <font color='#5555FF'>&</font><font color='#5555FF'>=</font> <font color='#979000'>0xf</font>; <font color='#009900'>// same as shift_amount %= 16; |
|
</font> |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> offset; <font color='#009900'>// result |
|
</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> s <font color='#5555FF'>=</font> end <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; <font color='#009900'>// source |
|
</font> <font color='#0000FF'>const</font> uint32 temp <font color='#5555FF'>=</font> <font color='#979000'>16</font> <font color='#5555FF'>-</font> shift_amount; |
|
|
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#5555FF'>-</font>s<font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> temp<font face='Lucida Console'>)</font>; |
|
<font color='#009900'>// set the number of digits used in the result |
|
</font> <font color='#009900'>// if the upper bits from *s were zero then don't count this first word |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> offset; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> offset <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>s <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font face='Lucida Console'>(</font><font color='#5555FF'>*</font>s <font color='#5555FF'><</font><font color='#5555FF'><</font> shift_amount<font face='Lucida Console'>)</font> <font color='#5555FF'>|</font> <font face='Lucida Console'>(</font> <font color='#5555FF'>*</font><font face='Lucida Console'>(</font>s<font color='#5555FF'>-</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>></font><font color='#5555FF'>></font> temp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>s; |
|
<b>}</b> |
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s <font color='#5555FF'><</font><font color='#5555FF'><</font> shift_amount; |
|
|
|
<font color='#009900'>// now zero the rest of the result |
|
</font> end <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>r <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<font color='#5555FF'>*</font><font face='Lucida Console'>(</font><font color='#5555FF'>-</font><font color='#5555FF'>-</font>r<font face='Lucida Console'>)</font> <font color='#5555FF'>=</font> <font color='#979000'>0</font>; |
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='shift_right'></a>shift_right</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> data, |
|
data_record<font color='#5555FF'>*</font> result |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
|
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> result<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; <font color='#009900'>// result |
|
</font> uint16<font color='#5555FF'>*</font> s <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; <font color='#009900'>// source |
|
</font> uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> s <font color='#5555FF'>+</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>s <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>s <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'>|</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font><font face='Lucida Console'>(</font>s<font color='#5555FF'>+</font><font color='#979000'>1</font><font face='Lucida Console'>)</font> <font color='#5555FF'><</font><font color='#5555FF'><</font> <font color='#979000'>15</font><font face='Lucida Console'>)</font>; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<b>}</b> |
|
<font color='#5555FF'>*</font>r <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s <font color='#5555FF'>></font><font color='#5555FF'>></font> <font color='#979000'>1</font>; |
|
|
|
|
|
<font color='#009900'>// calculate the new number for digits_used |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>r <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>else</font> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
result<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> data<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
|
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> bigint_kernel_2:: |
|
<b><a name='is_less_than'></a>is_less_than</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
uint32 lhs_digits_used <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
uint32 rhs_digits_used <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
|
|
<font color='#009900'>// if lhs is definitely less than rhs |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lhs_digits_used <font color='#5555FF'><</font> rhs_digits_used <font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#009900'>// if lhs is definitely greater than rhs |
|
</font> <font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lhs_digits_used <font color='#5555FF'>></font> rhs_digits_used<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> l <font color='#5555FF'>=</font> end <font color='#5555FF'>+</font> lhs_digits_used; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number <font color='#5555FF'>+</font> rhs_digits_used; |
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>l <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>l; |
|
<font color='#5555FF'>-</font><font color='#5555FF'>-</font>r; |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>l <font color='#5555FF'><</font> <font color='#5555FF'>*</font>r<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<font color='#0000FF'>else</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>l <font color='#5555FF'>></font> <font color='#5555FF'>*</font>r<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// at this point we know that they are equal |
|
</font> <font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<b>}</b> |
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>bool</u></font> bigint_kernel_2:: |
|
<b><a name='is_equal_to'></a>is_equal_to</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> lhs, |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> rhs |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#009900'>// if lhs and rhs are definitely not equal |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>!</font><font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
uint16<font color='#5555FF'>*</font> l <font color='#5555FF'>=</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> r <font color='#5555FF'>=</font> rhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> l <font color='#5555FF'>+</font> lhs<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
|
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>l <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>l <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#5555FF'>*</font>r<font face='Lucida Console'>)</font> |
|
<font color='#0000FF'>return</font> <font color='#979000'>false</font>; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>l; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>r; |
|
<b>}</b> |
|
|
|
<font color='#009900'>// at this point we know that they are equal |
|
</font> <font color='#0000FF'>return</font> <font color='#979000'>true</font>; |
|
<b>}</b> |
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='increment'></a>increment</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> source, |
|
data_record<font color='#5555FF'>*</font> dest |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
uint16<font color='#5555FF'>*</font> s <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> d <font color='#5555FF'>=</font> dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> s <font color='#5555FF'>+</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>d <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#009900'>// if there was no carry then break out of the loop |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>d <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
|
|
<font color='#009900'>// copy the rest of the digits over to d |
|
</font> <font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>s <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>d <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<b>}</b> |
|
|
|
<font color='#0000FF'>break</font>; |
|
<b>}</b> |
|
|
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
|
|
<font color='#009900'>// if we have hit the end of s and there was a carry up to this point |
|
</font> <font color='#009900'>// then just make the next digit 1 and add one to the digits used |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>s <font color='#5555FF'>=</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>+</font> <font color='#979000'>1</font>; |
|
<font color='#5555FF'>*</font>d <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>break</font>; |
|
<b>}</b> |
|
|
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='decrement'></a>decrement</b> <font face='Lucida Console'>(</font> |
|
<font color='#0000FF'>const</font> data_record<font color='#5555FF'>*</font> source, |
|
data_record<font color='#5555FF'>*</font> dest |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
uint16<font color='#5555FF'>*</font> s <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> d <font color='#5555FF'>=</font> dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>number; |
|
uint16<font color='#5555FF'>*</font> end <font color='#5555FF'>=</font> s <font color='#5555FF'>+</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font><font color='#979000'>true</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>d <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#009900'>// if there was no carry then break out of the loop |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>d <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0xFFFF</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// if we lost a digit in the subtraction |
|
</font> <font color='#0000FF'>if</font> <font face='Lucida Console'>(</font><font color='#5555FF'>*</font>d <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>0</font> <font color='#5555FF'>&</font><font color='#5555FF'>&</font> s<font color='#5555FF'>+</font><font color='#979000'>1</font> <font color='#5555FF'>=</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>if</font> <font face='Lucida Console'>(</font>source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>else</font> |
|
dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>-</font> <font color='#979000'>1</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
dest<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used <font color='#5555FF'>=</font> source<font color='#5555FF'>-</font><font color='#5555FF'>></font>digits_used; |
|
<b>}</b> |
|
<font color='#0000FF'>break</font>; |
|
<b>}</b> |
|
<font color='#0000FF'>else</font> |
|
<b>{</b> |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<b>}</b> |
|
|
|
<b>}</b> |
|
|
|
<font color='#009900'>// copy the rest of the digits over to d |
|
</font> <font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<font color='#0000FF'>while</font> <font face='Lucida Console'>(</font>s <font color='#5555FF'>!</font><font color='#5555FF'>=</font> end<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#5555FF'>*</font>d <font color='#5555FF'>=</font> <font color='#5555FF'>*</font>s; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>d; |
|
<font color='#5555FF'>+</font><font color='#5555FF'>+</font>s; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='fft'></a>fft</b> <font face='Lucida Console'>(</font> |
|
ct<font color='#5555FF'>*</font> data, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> len |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> t pi2 <font color='#5555FF'>=</font> <font color='#5555FF'>-</font><font color='#979000'>2.0</font><font color='#5555FF'>*</font><font color='#979000'>3.1415926535897932384626433832795028841971693993751</font>; |
|
|
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> half <font color='#5555FF'>=</font> len<font color='#5555FF'>/</font><font color='#979000'>2</font>; |
|
|
|
std::vector<font color='#5555FF'><</font>ct<font color='#5555FF'>></font> twiddle_factors; |
|
twiddle_factors.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>half<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// compute the complex root of unity w |
|
</font> <font color='#0000FF'>const</font> t temp <font color='#5555FF'>=</font> pi2<font color='#5555FF'>/</font>len; |
|
ct w <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>cos</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>,std::<font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
ct w_pow <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#009900'>// compute the twiddle factors |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>std::vector<font color='#5555FF'><</font>ct<font color='#5555FF'>></font>::size_type j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> twiddle_factors.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
twiddle_factors[j] <font color='#5555FF'>=</font> w_pow; |
|
w_pow <font color='#5555FF'>*</font><font color='#5555FF'>=</font> w; |
|
<b>}</b> |
|
|
|
ct a, b; |
|
|
|
<font color='#009900'>// now compute the decimation in frequency. This first |
|
</font> <font color='#009900'>// outer loop loops log2(len) number of times |
|
</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> skip <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> step <font color='#5555FF'>=</font> half; step <font color='#5555FF'>!</font><font color='#5555FF'>=</font> <font color='#979000'>0</font>; step <font color='#5555FF'>></font><font color='#5555FF'>></font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// do blocks of butterflies in this loop |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> len; j <font color='#5555FF'>+</font><font color='#5555FF'>=</font> step<font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// do step butterflies |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'><</font> step; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> a_idx <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font>k; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> b_idx <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font>k<font color='#5555FF'>+</font>step; |
|
a <font color='#5555FF'>=</font> data[a_idx] <font color='#5555FF'>+</font> data[b_idx]; |
|
b <font color='#5555FF'>=</font> <font face='Lucida Console'>(</font>data[a_idx] <font color='#5555FF'>-</font> data[b_idx]<font face='Lucida Console'>)</font><font color='#5555FF'>*</font>twiddle_factors[k<font color='#5555FF'>*</font>skip]; |
|
data[a_idx] <font color='#5555FF'>=</font> a; |
|
data[b_idx] <font color='#5555FF'>=</font> b; |
|
<b>}</b> |
|
<b>}</b> |
|
skip <font color='#5555FF'>*</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<font color='#0000FF'><u>void</u></font> bigint_kernel_2:: |
|
<b><a name='ifft'></a>ifft</b><font face='Lucida Console'>(</font> |
|
ct<font color='#5555FF'>*</font> data, |
|
<font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> len |
|
<font face='Lucida Console'>)</font> <font color='#0000FF'>const</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> t pi2 <font color='#5555FF'>=</font> <font color='#979000'>2.0</font><font color='#5555FF'>*</font><font color='#979000'>3.1415926535897932384626433832795028841971693993751</font>; |
|
|
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> half <font color='#5555FF'>=</font> len<font color='#5555FF'>/</font><font color='#979000'>2</font>; |
|
|
|
std::vector<font color='#5555FF'><</font>ct<font color='#5555FF'>></font> twiddle_factors; |
|
twiddle_factors.<font color='#BB00BB'>resize</font><font face='Lucida Console'>(</font>half<font face='Lucida Console'>)</font>; |
|
|
|
<font color='#009900'>// compute the complex root of unity w |
|
</font> <font color='#0000FF'>const</font> t temp <font color='#5555FF'>=</font> pi2<font color='#5555FF'>/</font>len; |
|
ct w <font color='#5555FF'>=</font> <font color='#BB00BB'>ct</font><font face='Lucida Console'>(</font>std::<font color='#BB00BB'>cos</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font>,std::<font color='#BB00BB'>sin</font><font face='Lucida Console'>(</font>temp<font face='Lucida Console'>)</font><font face='Lucida Console'>)</font>; |
|
|
|
ct w_pow <font color='#5555FF'>=</font> <font color='#979000'>1</font>; |
|
|
|
<font color='#009900'>// compute the twiddle factors |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font>std::vector<font color='#5555FF'><</font>ct<font color='#5555FF'>></font>::size_type j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> twiddle_factors.<font color='#BB00BB'>size</font><font face='Lucida Console'>(</font><font face='Lucida Console'>)</font>; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>j<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
twiddle_factors[j] <font color='#5555FF'>=</font> w_pow; |
|
w_pow <font color='#5555FF'>*</font><font color='#5555FF'>=</font> w; |
|
<b>}</b> |
|
|
|
ct a, b; |
|
|
|
<font color='#009900'>// now compute the inverse decimation in frequency. This first |
|
</font> <font color='#009900'>// outer loop loops log2(len) number of times |
|
</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> skip <font color='#5555FF'>=</font> half; |
|
<font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> step <font color='#5555FF'>=</font> <font color='#979000'>1</font>; step <font color='#5555FF'><</font><font color='#5555FF'>=</font> half; step <font color='#5555FF'><</font><font color='#5555FF'><</font><font color='#5555FF'>=</font> <font color='#979000'>1</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// do blocks of butterflies in this loop |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> j <font color='#5555FF'>=</font> <font color='#979000'>0</font>; j <font color='#5555FF'><</font> len; j <font color='#5555FF'>+</font><font color='#5555FF'>=</font> step<font color='#5555FF'>*</font><font color='#979000'>2</font><font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#009900'>// do step butterflies |
|
</font> <font color='#0000FF'>for</font> <font face='Lucida Console'>(</font><font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> k <font color='#5555FF'>=</font> <font color='#979000'>0</font>; k <font color='#5555FF'><</font> step; <font color='#5555FF'>+</font><font color='#5555FF'>+</font>k<font face='Lucida Console'>)</font> |
|
<b>{</b> |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> a_idx <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font>k; |
|
<font color='#0000FF'>const</font> <font color='#0000FF'><u>unsigned</u></font> <font color='#0000FF'><u>long</u></font> b_idx <font color='#5555FF'>=</font> j<font color='#5555FF'>+</font>k<font color='#5555FF'>+</font>step; |
|
data[b_idx] <font color='#5555FF'>*</font><font color='#5555FF'>=</font> twiddle_factors[k<font color='#5555FF'>*</font>skip]; |
|
a <font color='#5555FF'>=</font> data[a_idx] <font color='#5555FF'>+</font> data[b_idx]; |
|
b <font color='#5555FF'>=</font> data[a_idx] <font color='#5555FF'>-</font> data[b_idx]; |
|
data[a_idx] <font color='#5555FF'>=</font> a; |
|
data[b_idx] <font color='#5555FF'>=</font> b; |
|
<b>}</b> |
|
<b>}</b> |
|
skip <font color='#5555FF'>/</font><font color='#5555FF'>=</font> <font color='#979000'>2</font>; |
|
<b>}</b> |
|
<b>}</b> |
|
|
|
<font color='#009900'>// ---------------------------------------------------------------------------------------- |
|
</font> |
|
<b>}</b> |
|
<font color='#0000FF'>#endif</font> <font color='#009900'>// DLIB_BIGINT_KERNEL_2_CPp_ |
|
</font> |
|
|
|
</pre></body></html> |