Code:
var atan = Math.atan;
var tan = Math.tan;
var pi = Math.PI;
var ln = Math.log;
var exp = Math.exp;
function ceil(x){
return (sgn(x))*(abs(x)+.5+div(atan(-tan(pi*(abs(x)+.5))),pi))+(x<0?1:0);
}
function floor(x){
return -ceil(-x);
}
function abs(x){
return sgn(x)*x;
}
function sgn(x){
return (x<0)?-1:(x>0)?1:0;
}
function div(x,y){
return x/y;
}
function sin(y){
var sign = sgn(y);
var x = abs(y);
while(x>2*pi){
x-=2*pi;
}
return (x - (pow(x,3)/fac(3)) + (pow(x,5)/fac(5)) - (pow(x,7)/fac(7)) + (pow(x,9)/fac(9)) - (pow(x,11)/fac(11)) + (pow(x,13)/fac(13)) - (pow(x,15)/fac(15)) + (pow(x,17)/fac(17)))*sign;
}
function cos(y){
var sign = sgn(y);
var x = abs(y);
while(x>2*pi){
x-=2*pi;
}
return (1 - (pow(x,2)/fac(2)) + (pow(x,4)/fac(4)) - (pow(x,6)/fac(6)) + (pow(x,8)/fac(8)) - (pow(x,10)/fac(10)) + (pow(x,12)/fac(12)) - (pow(x,14)/fac(14)) + (pow(x,16)/fac(16)))*sign;
}
function sec(x){
return 1/cos(x);
}
function csc(x){
return 1/sin(x);
}
function fac(x){
return product(1,x,"#");
}
function product(start,end,transform,inst){
var inst = inst || "#";
var out = 1;
transform = transform.split("");
for(i=0;i<transform.length;i++){
transform[i] = transform[i].replace(inst,"i");
}
transform = transform.join("");
for(i=start;i<=end;i++){
out*=eval(transform);
}
return out;
}
function sum(start,end,transform,inst){
var inst = inst || "#";
var out = 1;
transform = transform.split("");
for(i=0;i<transform.length;i++){
transform[i] = transform[i].replace(inst,"i");
}
transform = transform.join("");
for(i=start;i<=end;i++){
out+=eval(transform);
}
return out;
}
function pow(x,y){
return truncIf(x+y,exp(y*ln(x)));
}
function trunc(x){
return +(x+"").split(".")[0];
}
function truncIf(x,y){
return (trunc(x)==x)?trunc(y):y;
}