itpp provides a pow2(int) function which basically returns (1<<n). as i'm sure you're already aware, this is much, much faster than the standard pow
function provided by libm. however, i've developed an ever-so-slightly faster version of pow2 that, instead of bit-shifting, uses a lookup table
for values of -32<n<32. from my initial experiments, this method is marginally faster, and with proper coding should inline itself fairly nicely.
however, the real motivation for switching to this method is not for the marginal improvement; it also opens some new possibilities:
(1) this method can be used for negative powers of two as well as positive ones. currently pow2 returns 0 if n < 0, and HUGEVAL if n > INT_MAX
(2) this method can also be used to develop a faster version of the libm ldexp function (double*2^int) as well
the only potential drawback is that it means having a table of 64 double values == 256 bytes in the data section of the executable, but from my
initial measurements it doesn't seem to have an adverse affect.
currently, i've implemented this outside of it++ and instead internally in the project i'm working on, but thought that it might be a good fit for it++ instead. what do you think?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
(1) this method can be used for negative powers of two as well as positive ones. currently pow2 returns 0 if n < 0, and HUGEVAL if n > INT_MAX
Yes, it's true. But it also means that your function needs to return a double to represent these negative powers.
> (2) this method can also be used to develop a faster version of the libm ldexp function (double*2^int) as well
As far as I know, ldexp() function is not used by any of the IT++ class or function now. So IT++ will not gain much of pow2(int) based on look-up table. But maybe end users, at least you, might find it useful :)
Anyway, if you have this function implemented, could you rework it a little bit to integrate with the IT++ SVN trunk sources? Then, please open a new feature request ticket and I will discuss with other developers if this should go to the mainline :) But I do not promise it will be accepted. Though, I have no objections now in including this.
Thanks!
/ediap
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
hey guys,
itpp provides a pow2(int) function which basically returns (1<<n). as i'm sure you're already aware, this is much, much faster than the standard pow
function provided by libm. however, i've developed an ever-so-slightly faster version of pow2 that, instead of bit-shifting, uses a lookup table
for values of -32<n<32. from my initial experiments, this method is marginally faster, and with proper coding should inline itself fairly nicely.
however, the real motivation for switching to this method is not for the marginal improvement; it also opens some new possibilities:
(1) this method can be used for negative powers of two as well as positive ones. currently pow2 returns 0 if n < 0, and HUGEVAL if n > INT_MAX
(2) this method can also be used to develop a faster version of the libm ldexp function (double*2^int) as well
the only potential drawback is that it means having a table of 64 double values == 256 bytes in the data section of the executable, but from my
initial measurements it doesn't seem to have an adverse affect.
currently, i've implemented this outside of it++ and instead internally in the project i'm working on, but thought that it might be a good fit for it++ instead. what do you think?
Hi Sean,
(1) this method can be used for negative powers of two as well as positive ones. currently pow2 returns 0 if n < 0, and HUGEVAL if n > INT_MAX
Yes, it's true. But it also means that your function needs to return a double to represent these negative powers.
> (2) this method can also be used to develop a faster version of the libm ldexp function (double*2^int) as well
As far as I know, ldexp() function is not used by any of the IT++ class or function now. So IT++ will not gain much of pow2(int) based on look-up table. But maybe end users, at least you, might find it useful :)
Anyway, if you have this function implemented, could you rework it a little bit to integrate with the IT++ SVN trunk sources? Then, please open a new feature request ticket and I will discuss with other developers if this should go to the mainline :) But I do not promise it will be accepted. Though, I have no objections now in including this.
Thanks!
/ediap