You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

72 lines
1.3 KiB

#include <stdio.h>
#include <limits.h>
#include <stdbool.h>
#include "exponent.h"
#include "logarithmus.h"
double absD(double x){
if(x<0){
return -1 * x;
}
return x;
}
double p(double exp, double base){
double prod = 1.0;
if(exp==0.0){
return 1;
}else{
for(int i = 1; i <= (int) exp; i++){
prod *= base;
}
return prod;
}
}
double powerD(double exp, double base){
if(absD(exp) - ((int) absD(exp)) < 0.000001){
if(exp>=0.0){
return p(exp, base);
}
else{
if (base == 0.0){
return -1.0;
}
return (1.0 / p((exp*-1), base));
}
}else if(base > 0.0){
if(exp>=0.0){
return exponential(exp*logN(base));
}
else{
if (base == 0.0){
return -1.0;
}
return (1.0 / exponential((-1*exp)*logN(base)));
}
}
return -1.0;
}
unsigned long long fac(int x){
unsigned long long prod = 1;
if(x==0) return 1;
for (int i = 1; i <= x; i++){
if (prod > ULLONG_MAX / i){
break;
}
prod*=i;
}
return prod;
}
double exponential(double x){
double sum = 0.0;
for(int i = 0; i<=21; i++){
sum += (1.0/fac(i)*(powerD(i,x)));
}
return sum;
}