I haven't kept up with C++ in a few years - what does constexpr do for local variables?
constexpr double a0 = 1.5707288;
show comments
jaen
Cool, although more ILP (instruction-level parallelism) might not necessarily be better on a modern GPU, which doesn't have much ILP, if any (instead it uses those resources to execute several threads in parallel).
That might explain why the original Cg (a GPU programming language) code did not use Estrin's, since at least the code in the post does add 1 extra op (squaring `abs_x`).
(AMD GPUs used to use VLIW (very long instruction word) which is "static" ILP).
jagged-chisel
> It also gets in the way of elegance and truth.
That’s quite subjective. I happen to find trigonometry to be elegant and true.
I also agree that trigonometric functions lack efficiency in software.
show comments
fatih-erikli-cg
I think it is `atan` function. Sin is almost a lookup query.
show comments
thomasahle
Did you try polynomial preprocessing methods, like Knuth's and Estrin's methods?
https://en.wikipedia.org/wiki/Polynomial_evaluation#Evaluati...
they let you compute polynomials with half the multiplications of Horner's method, and I used them in the past to improve the speed of the exponential function in Boost.
A notable approximation of ~650 AD vintage, by Bhaskara is
The search for better and better approximations led Indian mathematicians to independently develop branches of differential and integral calculus.This tradition came to its own as Madhava school of mathematics from Kerala. https://en.wikipedia.org/wiki/Kerala_school_of_astronomy_and...
Note the approximation is for 0 < x < 1. For the range [-1, 0] Bhaskara used symmetry.
If I remember correctly, Aryabhatta had derived a rational approximation about a hundred years before this.
EDIT https://doi.org/10.4169/math.mag.84.2.098
This is a followup of a different post from the same domain. 5 days ago, 134 comments https://news.ycombinator.com/item?id=47336111
No idea if it's not already optimised, but x2 could also be x*x and not just abs_x * abs_x, shifting the dependencies earlier.
I've been thinking about this since [1] the other day, but I still love how rotation by small angles lets you drop trig entirely.
Let α represent a roll rotation, and β a pitch rotation.
Let R(α) be:
Let R(β) be: Combine them: But! For small α and β, just approximate: So now: [1]https://news.ycombinator.com/item?id=47348192I haven't kept up with C++ in a few years - what does constexpr do for local variables?
Cool, although more ILP (instruction-level parallelism) might not necessarily be better on a modern GPU, which doesn't have much ILP, if any (instead it uses those resources to execute several threads in parallel).
That might explain why the original Cg (a GPU programming language) code did not use Estrin's, since at least the code in the post does add 1 extra op (squaring `abs_x`).
(AMD GPUs used to use VLIW (very long instruction word) which is "static" ILP).
> It also gets in the way of elegance and truth.
That’s quite subjective. I happen to find trigonometry to be elegant and true.
I also agree that trigonometric functions lack efficiency in software.
I think it is `atan` function. Sin is almost a lookup query.
Did you try polynomial preprocessing methods, like Knuth's and Estrin's methods? https://en.wikipedia.org/wiki/Polynomial_evaluation#Evaluati... they let you compute polynomials with half the multiplications of Horner's method, and I used them in the past to improve the speed of the exponential function in Boost.