Can you provide a bit more detail on the exponentiation by squaring?
How would I re-write my simple c++ loop above using your method?
On Mon, Aug 18, 2014 at 2:30 PM, Chen-Pang He <jdh8@xxxxxxxxxxxxxx
If you need no optimization and want functional programming,
ArrayBase::unaryExpr with a homemade functor is enough.
If you need optimization, because all exponents are integers,
binary powering (aka exponentiation by squaring) is *the*
algorithm. We can reuse `pow(delta, (1 << k))`.
在 2014 八月 18 週一 13:42:46，Ian Bell 寫道:
> On Mon, Aug 18, 2014 at 1:28 PM, Christoph Hertzberg <
> > On 18.08.2014 00:23, Ian Bell wrote:
> >> cross-posted to stack overflow...
> > If you cross-post, could you post a link as well?
> Here's the link:
> > I need to raise a double value to an array of integer
powers, in c++ this
> >> would look something like
> > Could you be a bit more specific about the "array of integer
> > guess 'exponents')?
> > If they are a sequence 0,1,2,3,... your proposed solution is
> > very inefficient. If they are of great range, with no
apparent pattern, I
> > would say the exp(log(delta)*exponent) approach is basically
> > efficient solution (maybe using log2 and exp2 would be more
> > they were available).
> The exponents are typically in the range [0, 10), and can be
sorted if that
> is of use. They are not necessarily linearly increasing, we
> exponents 0,0,0,1,1,1,1,2,2 for instance. Obviously it would be
> short-circuit the 0 powers as well since they yield 1 again
> method with the exp(log(delta)*exponent) also doesn't allow you
> those powers. I think that the >0 comparison should be cheaper
> pow(x, 0) when 0 is integer. Especially this will be true when
何震邦 | jdh8@xxxxxxxxxxxxxx <mailto:jdh8@xxxxxxxxxxxxxx> |