Compare commits

...

No commits in common. 'sin' and 'master' have entirely different histories.
sin ... master

@ -1,91 +0,0 @@
package sin;
public class Sin {
public static double number;
public static double PI = 3.14159265358979323846;
public Sin() {
}
public static double sin(double num) {
double tmp = Math.toRadians(num);
number=Math.sin(tmp);
return number;
}
public static double cos(double num) {
double tmp = Math.toRadians(num);
return Math.cos(tmp);
}
public static double mysin(double x)
{
while(x>2*PI) x -= 2*PI;
while(x<0) x += 2*PI;
double index, result=0;
int i=1;
do{
index = mypow(x,i) / factorial(i);
result += mypow(-1,i/2) * index;
i += 2;
}
while(index>1e-6);
return result;
}
public static double factorial(double i) {
if(i==0)
return 1;
else
return i*factorial(i-1);
}
public static double mypow(double x,int i) {
if(i>0)
return x*mypow(x, i-1);
else if(i<0)
return 1/x*mypow(x, i+1);
else
return 1;
}
public static double mycos(double x) {
while(x>2*PI) x -= 2*PI;
while(x<0) x += 2*PI;
double index, result=0;
int i=0;
do{
index = mypow(x,i) / factorial(i);
result += mypow(-1,i/2) * index;
i += 2;
}
while(index>1e-6);
return result;
}
public static double toRadians(double angdeg) {
return angdeg / 180.0 * PI;
}
public static void main(String[] args) {
System.out.println(mysin(toRadians(30)));
System.out.println(mycos(30));
}
}

@ -0,0 +1,7 @@
public class mypow{
double e,x;
public double mypow(double e,double x) {
double ans=Math.pow(e, x);
return ans;
}
}
Loading…
Cancel
Save