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).
constexpr double a0 = 1.5707288;Maybe it's folded into expressions, propagated through constant expressions, or used it in contexts that require compile-time constants (template parameters, array sizes, static_assert, other constexpr expressions).
I mean, not in this case of pi/2, where it's more about announcing semantics, but in general those are the purposes and uses.
Something like a struct that I can say "this struct is global to the whole program and everyone can see it, but once this function exits those values are locked in". Maybe something like that one function is allowed to unlock and update it, but nowhere else.
Think in terms of storing a bunch of precomputed coefficients that are based on the samplerate of a system, where you really only need to set it up once on startup and it is unlikely to change during the application's running lifetime.
I feel like there probably is a way to do this, and if I was good at high level languages like C I'd know what it is. If you know, tell me what I'm not understanding ;-)
An optimizing compiler might see through a non-constexpr declaration like 'double a0 = ...' or it might not. Constexpr is somewhat more explicit, especially with more complicated initializer expressions.
ArcCos(x)= Π √((1-x)/(4+x)).
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.
That’s quite subjective. I happen to find trigonometry to be elegant and true.
I also agree that trigonometric functions lack efficiency in software.
Where did that come from in the article?
The only thing I remember at this point is that I copied and pasted that sentence (I didn't type it.) Even search doesn't find the sentence anywhere but HN.
Let α represent a roll rotation, and β a pitch rotation.
Let R(α) be:
( cos α sin α 0)
(-sin α cos α 0)
( 0 0 1)
Let R(β) be: (1 0 0 )
(0 cos β -sin β)
(0 sin β cos β)
Combine them: R(β).R(α) = ( cos α sin α 0 )
((-sin α*cos β) (cos α*cos β) -sin β)
((-sin α*sin β) (cos α*sin β) cos β)
But! For small α and β, just approximate: ( 1 α 0)
(-α 1 -β)
( 0 β 1)
So now: x' = x + αy
y' = y - αx - βz
z' = z + βy
[1]https://news.ycombinator.com/item?id=47348192This is a great technique for cheaply doing 3D starfields etc on 8-bit machines.
Look ma, no sine table!
Large angular deflections while being linear transforms, do not in general commute.
It will spoil the linear relation in your elegant expression, but a slightly better approximation for cos for small θ is
1 - 0.5θ²
fatih-erikli-cg•5h ago
xyzzyz•5h ago
fatih-erikli-cg•5h ago
Sin/cos must be borders of sqrt(x²+y²). It is also cached indeed.
groundzeros2015•4h ago
We can compute these things using iteration or polynomial approximations (sufficient for 64 bit).
fatih-erikli-cg•27m ago
BigTTYGothGF•1h ago
This doesn't make a ton of sense.
fatih-erikli-cg•35m ago
I think it is stored like sintable[deg]. The degree is index.
connicpu•4h ago
somat•2h ago
If curious, On a N64 the graphics chip is also the memory controller so every thing the cpu can do to stay off the memory bus has an additive effect allowing the graphics to do more graphics. This is also why the n64 has weird 9-bit ram, it is so they could use a 18-bit pixel format, only taking two bytes per pixel, for cpu requests the memory controller ignored the 9th bit, presenting a normal 8 bit byte.
They were hoping that by having high speed memory, 250 mHz, the cpu ran at 90mHz, it could provide for everyone and it did ok, there are some very impressive games on the n64. but on most of them the cpu is running fairly light, gotta stay off that memory bus.
https://www.youtube.com/watch?v=xFKFoGiGlXQ (Kaze Emanuar: Finding the BEST sine function for Nintendo 64)
gzread•2h ago
ErroneousBosh•31m ago
The Ensoniq EPS sampler (the first version) used 13-bit RAM for sample memory. Why 13 and not 12? Who knows? Possibly because they wanted it "one louder", possibly because the Big Rival in the E-Mu Emulator series used μ-law codecs which have the same effective dynamic range as 13-bit linear.
Anyway you read a normal 16-bit word using the 68000's normal 16-bit instructions but only the upper 13 were actually valid data for the RAM, the rest were tied low. Haha, no code space for you!