r/cpp • u/def-pri-pub • Mar 11 '26
Faster asin() Was Hiding In Plain Sight
https://16bpp.net/blog/post/faster-asin-was-hiding-in-plain-sight/
55
Upvotes
r/cpp • u/def-pri-pub • Mar 11 '26
20
u/jk-jeon Mar 12 '26
Great article, but I can't help but to point out a stupid nitpick. Calling the degree 9 Taylor polynomial "the 4th order" triggers my overly pedantic brain. I mean, you would call it either the 9th order, or the one with the first 5 nonzero terms. I think "4th order" doesn't sound correct in any sane interpretation of the term.
4
u/saf_e Mar 11 '26
I'm wondering, since its approximation anyway, why not to use floats?
2
u/owjfaigs222 Mar 12 '26
Soo will someone update the std lib? Or will people, forever into the future have to search for it to find it?
10
u/kammce WG21 | 🇺🇲 NB | Boost | Exceptions Mar 11 '26
Great article. I also learned something.
27
u/sweetno Mar 11 '26
Taylor series are never a starting point in numerical methods. Newton–Raphson is the gold standard, and applies to a wide range of functions.
4
u/Tringi github.com/tringi Mar 12 '26
The lessons about people not bothering to contribute corrections to even prominent projects, and great discoveries and innovations being stuffed somewhere hidden and their creators never credited nor praised, are sadly as old as time.
1
u/eta76 Mar 23 '26
Nice articles you have, I am always interested in performance validations.
Long ago I worked on a wavemodel (ocean like) and tried different optimizations. In our case a small lookup table was choosen, but another interesting performance hit was introduced by converting a double to int. This trick gave great performance, see:
https://stackoverflow.com/questions/17035464/a-fast-method-to-round-a-double-to-a-32-bit-int-explained
https://stackoverflow.com/questions/41144668/how-to-efficiently-perform-double-int64-conversions-with-sse-avx
In my case converting from double=>float=>'int' was even faster, but less correct since we where using large coordinates.
Looking through :
PSRayTracing-master\PSRayTracing-master\render_library\Perlin.cpp
PSRayTracing-master\PSRayTracing-master\render_library\PerlinReal.cpp
I noticed this, which could benefit from the optimization:
rreal Perlin::noise(const Vec3 &p) const NOEXCEPT {
const auto i = static_cast<int>(floor(p.x));
const auto j = static_cast<int>(floor(p.y));
const auto k = static_cast<int>(floor(p.z));
const rreal u = p.x - static_cast<rreal>(i);
const rreal v = p.y - static_cast<rreal>(j);
const rreal w = p.z - static_cast<rreal>(k);
But then I wondered, why converting from a 'floored-double' to int, just to convert it back to a double again? Can't you just use the floored-double, skipping the expensive double->int?
0
u/[deleted] Mar 11 '26
[deleted] — view deleted comment
0
u/[deleted] Mar 11 '26
[deleted] — view deleted comment