1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
const long double factorial(double a)
{
if(a > 1) return(a * factorial(a - 1));
else return(1);
}
const double sq(const double a)
{
return(a*a);
}
const double cb(const double a)
{
return(a*a*a);
}
const double power(double a, int b)
{
bool return2 = false;
double value = a;
if(b < 0)
{
b = absolute(b);
return2 = true;
}
for(unsigned int i = 1; i<b; i++) a *= value;
if(return2)
a = inverse(a);
if(b != 0)
return(a);
if(b == 0)
return(1);
}
const double power(double a, double b)
{
//fraction(a);
bool return2 = false;
double value = a;
if(b < 0)
{
b = absolute(b);
return2 = true;
}
for(unsigned int i = 1; i<b; i++)
a *= value;
if(return2)
a = inverse(a);
return(a);
}
const double sqrt(const double a)
{
double i = 0;
while(a - .01 > sq(i)) i += .001;
return(i);
}
const double cbrt(const double a)
{
double i = 0;
while(a - .01 > cb(i)) i += .001;
return(i);
}
const double root(const double a, const double b)
{
double i = 0;
while(a - .01 > power(i,b)) i += .001;
return(i);
}
const double e()
{
double e = 1, num = 1;
for(unsigned int i = 1; i<11; i++)
{
num *= i;
e += 1/(num);
}
return(e);
}
const double pi()
{
return((double)22/7);
}
const double absolute(double a)
{
if(a < 0) a *= -1;
return(a);
}
const double inverse(double a)
{
return(1/a);
}
const signed int characteristic(const double a)
{
std::string number = intToString(a), leftNumber;
unsigned int decimalAt = 0, leftOfDecimal;
for(unsigned int i = 0; i<number.size(); i++) if(number[i] == '.') decimalAt = i;
if(decimalAt == 0) number.append(".0");
for(unsigned int i = 0; i<number.size(); i++) if(number[i] == '.') leftOfDecimal = i+1;
for(unsigned int i = 0; i < leftOfDecimal; i++) leftNumber.push_back(number[i]);
return(atoi(leftNumber.c_str()));
}
const unsigned int mantissa(const double a)
{
std::string number = intToString(a), leftNumber;
int leftOfDecimal;
for(unsigned int i = 0; i<number.size(); i++) if(number[i] == '.') leftOfDecimal = i;
for(unsigned int i = leftOfDecimal+1; i < number.size(); i++) leftNumber.push_back(number[i]);
return(atoi(leftNumber.c_str()));
}
const std::string intToString(double a)
{
std::stringstream ss;
std::string str;
ss << std::setprecision(10) << a;
ss >> std::setprecision(10) >> str;
return(str);
}
const unsigned int gcf(const double a, const double b)
{
unsigned int gcf, smallest = smallestNumber(a, b), largest = largestNumber(a, b);
for(unsigned int i = 1; i<smallest+1; i++) if(smallest % i == 0 && largest % i == 0) gcf = i;
return(gcf);
}
const double smallestNumber(const double a, const double b)
{
double smallest;
if(a > b) smallest = b;
else smallest = a;
return(smallest);
}
const double largestNumber(const double a, const double b)
{
double largest;
if(a > b) largest = a;
else largest = b;
return(largest);
}
|