Ilya Zakharevich on Mon, 16 Sep 2024 19:43:29 +0200 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Re: A missing (?) function: exponentfp(x) |
On Sat, Sep 14, 2024 at 12:31:57PM +0200, Loïc Grenié wrote: > In gp you can cheat > > ? install(dbllog2,lG); > ? install(dbltor,L); > ? flog2(x)=dbltor(dbllog2(x)); > ? my(il2=1/log(2));setrand(1);for(i=1,10^6,log(random(1.)<<4)*il2) > cpu time = 3,868 ms, real time = 3,868 ms. > ? setrand(1);for(i=1,10^6,flog2(random(1.)<<4)) > cpu time = 655 ms, real time = 656 ms. Moreover, on my CPU, exponent() is 400 times quicker than log()/log(2). So your 5x speedup is still “more or less negligible”! (A partial aside: In my vita, for a smooth user experience, there is an important aspect which is almost universally overlooked. I prefer to call it “gradual degradation”. For example, people often advocate as the preferred target to aim at: • It should be possible to be able to code the “required things”. • It should be simple to code the simple “required things”. With “gradual degradation”, one (or ≥1) more requirements appears: • It should be only moderately hard to code “required things” which are moderately hard. Without this, what usually happens is an almost insurmountable obstacle: ∘ as a test, you code something simple. It works! ∘ then you want to do more — but the amount of extra work to make even a small step forward is formidable. You give up! I would say that for a smooth progression, the coefficient should be about 3: the next step in the ladder should not require “more than 3x the effort” of the previous one.) Following this, I would think that having a flavor of exponent() which is at most 3x slower (but gives a continuous/or/C¹/or/piecewise-quadratic approximation to log2()) may be beneficial in many situations. Hope this helps, Ilya