- •1. Objectives of the Term Work
- •2. Basic Principles
- •2.1. Digital Logarithmic (dl) Representation
- •0(Zero)
- •Integer part Fractional part
- •2.2. Basic Rules of dl Arithmetic
- •2.3. Basic Algorithms of Data Processing
- •3. Models of Data Structures in the Main Memory
- •4. Processing the dl-type of Data in computer
- •Figure 4.1 Class Diagram
- •5. Solution of the task of term assignment
- •Figure 5.1. Snapshot of result.
- •Attachment. Source code of the developed class.
4. Processing the dl-type of Data in computer
In order to perform the task of term assignment it is necessary first to develop the representation of the DL data type in high level programming language.
For this purpose I have chosen the C++ language which yields great functionality for the object-oriented programming.
The most reasonable way of data type representation is the development of class representing it. The goal is to develop the class with high level of abstraction and reliability. The listing of the class is shown in attachment to the term paper. The structure of class is depicted on the figure 4.1 below:
Figure 4.1 Class Diagram
It is obvious that given class has only several public methods: constructors, destructor, overloaded arithmetic operators, assignment operator and method ToString(). All the other methods are private and can be called only from the public methods. Such a high abstraction level gives the user possibility to work with DL objects like with variables of type similar to double or integer.
5. Solution of the task of term assignment
The task of my term assignment is the calculation of sin(x) trigonometric function using the continued fraction method via DL representation of codes.
The sin(x) function may be represented by the Taylor’s series in following form:
So the task is to calculate the given sum by using this formula. Let the number of iterations n = 10. The source code of solution is:
#include "DLClass.h"
int main()
{
//the goal is to realize the function calculating sinx
double x=1.57; // the argument of the function x;
double factorial=1.0;// here we calculate the factorial
double sign=-1.0;//the sign
A1 numerator;
A1 denominator;
A1 sum=0.0;
A1 sign_DL;
A1 arg=x;
for(int n=0;n<10;n++)
{
//the numerator calculation
sign=-1.0;
sign=pow(sign,n);
sign_DL=sign;
numerator=x;
for(int i=1;i<2*n+1;i++)
{
numerator=numerator*arg;
}
numerator=numerator*sign_DL;
//the denominator calculation;
factorial=1.0;
for(int i=1;i<=2*n+1;i++)
{
factorial*=i;
}
denominator=factorial;
//now the sum is calculated
sum=sum+numerator/denominator;
}
char buf[256];
sum.ToString(buf);
printf("%s\n",buf);
return 1;
}
This code computes the sin(x) of 1.57 that is approximately pi over 2.
The
result is (fig.5.1):
Figure 5.1. Snapshot of result.
It’s obvious that simple transformation of this code allows the calculation of sinus function of any input argument with any number of iterations.
Calculations of such accuracy are impossible without using the DL codes.
Conclusion. During the execution of current term assignment we have learned the principles of operation and utilization of Digital Logarithmic Data representation. We have developed the convenient reliable C++ class describing DL arithmetic that can be used for calculations of any complexity. The task was to perform the example of high-accuracy calculations via DL. My task was the calculation of trigonometric function. Actually, the obtained results are more higher accurate than one can obtain by using standard means of C++ calculations and standard data types. Furth more, the developed class is good scalable – a lot of functions can be easily added by using already written ones: for example the function calculating sin(x) may be rewritten as the public method of this class. In such manner the logical and data-conversion methods can be added to. If such work is performed – the totally tested class may be incorporated into COM object and be redistributed for being used in any application written on the .NET platform.
