8 ms·
That is surprisingly bad. It reminds me of when I first heard that you could get fast sine/cosine approximations with table lookups -- not fully understanding
by haberman 15y ago
That is surprisingly bad. It reminds me of when I first heard that you could get fast sine/cosine approximations with table lookups -- not fully understanding this idea I wrote a program that generated the following (I was in high school, young and naive):
double sin(double x) {
if (x >= 0.00 && x < 0.01) return 0;
if (x >= 0.01 && x < 0.02) return 0.01;
// ...
}
- gcr 15y agoAt least you wrote the program to generate it rather than typing all that by hand. I think you got the gist of the idea. In any case, would all those branches be faster than the comparatively expensive floating-point arithmetic?
- Retric 15y agoNo, at best you could do a binary search using if's to simulate a lookup table, but you are going to trash the pipeline on a modern CPU if you want a reasonably complex lookup table you are much better off with something like: float lookup_Sine(x){ int I = 100 * (x mod 360); return sine_table(I); } Anyway, for a modern CPU hitting main memory takes a lot of cycles. So you need something a lot more complex than a simple trig function to make it worth it.