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.

25 lines
556 B

This file contains invisible Unicode characters!

This file contains invisible Unicode characters that may be processed differently from what appears below. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to reveal hidden characters.

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/**
* e的x次方的泰勒展开式为
* e^x=1+x/1!+x^2/2!+x^3/3!+…+x^n/n! 
**/
public class CalculateEx {
public static double calcalate(int x){
int n=1; //n用来算阶乘
long f=1; //总阶乘
double sum=1.0,temp=1.0; //sum为最终值temp算分子的次方
do{
f= f*n ;//阶乘
n++ ;
temp *= x; //计算次方
sum += temp / f;
} while(1.0/f>1e-6);
//System.out.println("e^"+x+"="+sum);
return sum;
}
}