function.java

master
zhouxiang 4 years ago
parent 053336bc55
commit ab897ed844

@ -0,0 +1,26 @@
public static double function(double x,int n){
if(x==0)
{
return 0.0;
}
if(n>0)
{
return Pow(x,n);
}
else
{
return 1/Pow(x,-n);
}
}
public static double Pow(double x,int n){
if(n==0)
return 1;
double tem=Pow(x,n/2);
if(n%2==0)
{
return tem*tem;
}
else{
return tem*tem*x;
}
}
Loading…
Cancel
Save