var atan = Math.atan;
var tan = Math.tan;
var pi = Math.PI;
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;
}
That's all for now, I hope to have more for you tomorrow.
Thursday, January 1, 2015
Challenge initiated: Let's re-create the Math object.
First, a public apology: I'm moving away from the syntax highlighter. Sorry, :(, but I don't have the time and energy to use it. So, just a grey-and-white PRE.
So, right now, I'm attempting at re-creating all of the functions in the Math object. Typically, this wouldn't be to hard, however; I am trying to define as much of the functions mathematically, that is, with equations, leaning only on the functions I define myself.
Currently, I have very few functions covered; I am also currently leaning slightly on the Math object for two functions and a variable: Math.atan, Math.tan, and Math.PI; I can easily define the last one, and possibly the second with a Taylor sequence, but I haven't gotten around to doing this.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment