Posts

Showing posts from 2012

User defined floating point data type

Here, I am giving a user defined data-type class Double. this does not require any underlying floating point data-type as it works on the String data type /* hi, check this out. this program does not implement any underlying floating point data type. this program just only works on the basic datatypes int_64, char and string so it will avoid the different answers on different platform */ /* using string to store a double value */ //keeping significand and exponent in direct decimal format #include <string> #include <cstring> #include <sstream> #include <iostream> using namespace std; class Decimal { char sign;      string significand;  int64_t exponent;    char ch; string str; public:       void print() //check how to overload <<       {            int64_t val=0;         ...

Logarithm in c++

#include<iostream> #define log10 2.30258509 using namespace std; double p(double x,int y)  //power function { int i; double res=1.0; for(i=1;i<=y;i++) { res*=x; } return res; } int dton(double *b)  //double to normalised to 10 form {          int a = *b; int bits = 0; while (a != 0) {     bits = bits + 1;     *b = *b / 10;     a= *b; } *b=(*b)*10; //cout<<"\n b in normalised form \n"<<b<<"* 10^"<<bits-1; return bits-1; }//end function void dton1(double b)  //double to normalised to 10 form {          int a = b; int bits = 0; while (a != 0) {     bits = bits + 1;     b = b / 10;     a= b; } b=b*10; cout<<"\n b in normalised form \n"<<b<<"* 10^"<<bits-1; }//end function void dton(double b)  //double to normalised to 2 form {       ...