Commit 0bf3fc17 authored by Mike Bostock's avatar Mike Bostock
Browse files

Optimize hyperbolic functions.

Not used much, but still an improvement. http://jsperf.com/hyperbolics
parent 68582505
......@@ -1169,13 +1169,13 @@ d3 = function() {
return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
}
function d3_sinh(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
return ((x = Math.exp(x)) - 1 / x) / 2;
}
function d3_cosh(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
return ((x = Math.exp(x)) + 1 / x) / 2;
}
function d3_tanh(x) {
return d3_sinh(x) / d3_cosh(x);
return ((x = Math.exp(2 * x)) - 1) / (x + 1);
}
function d3_haversin(x) {
return (x = Math.sin(x / 2)) * x;
......
This diff is collapsed.
......@@ -19,15 +19,15 @@ function d3_asin(x) {
}
function d3_sinh(x) {
return (Math.exp(x) - Math.exp(-x)) / 2;
return ((x = Math.exp(x)) - 1 / x) / 2;
}
function d3_cosh(x) {
return (Math.exp(x) + Math.exp(-x)) / 2;
return ((x = Math.exp(x)) + 1 / x) / 2;
}
function d3_tanh(x) {
return d3_sinh(x) / d3_cosh(x);
return ((x = Math.exp(2 * x)) - 1) / (x + 1);
}
function d3_haversin(x) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment