Fixed point binary exponential. This uses the BKM algorithm in E-mode. \param m exponent in [0,1) as Q0.31 \param n number of iterations (at most 32) \return 2 ^ \a m as Q1.31
| 1502 | /// \param n number of iterations (at most 32) |
| 1503 | /// \return 2 ^ \a m as Q1.31 |
| 1504 | inline uint32 exp2(uint32 m, unsigned int n = 32) |
| 1505 | { |
| 1506 | static const uint32 logs[] = { |
| 1507 | 0x80000000, 0x4AE00D1D, 0x2934F098, 0x15C01A3A, 0x0B31FB7D, 0x05AEB4DD, 0x02DCF2D1, 0x016FE50B, |
| 1508 | 0x00B84E23, 0x005C3E10, 0x002E24CA, 0x001713D6, 0x000B8A47, 0x0005C53B, 0x0002E2A3, 0x00017153, |
| 1509 | 0x0000B8AA, 0x00005C55, 0x00002E2B, 0x00001715, 0x00000B8B, 0x000005C5, 0x000002E3, 0x00000171, |
| 1510 | 0x000000B9, 0x0000005C, 0x0000002E, 0x00000017, 0x0000000C, 0x00000006, 0x00000003, 0x00000001 }; |
| 1511 | if(!m) |
| 1512 | return 0x80000000; |
| 1513 | uint32 mx = 0x80000000, my = 0; |
| 1514 | for(unsigned int i=1; i<n; ++i) |
| 1515 | { |
| 1516 | uint32 mz = my + logs[i]; |
| 1517 | if(mz <= m) |
| 1518 | { |
| 1519 | my = mz; |
| 1520 | mx += mx >> i; |
| 1521 | } |
| 1522 | } |
| 1523 | return mx; |
| 1524 | } |
| 1525 | |
| 1526 | /// Fixed point binary logarithm. |
| 1527 | /// This uses the BKM algorithm in L-mode. |