Fixed point binary logarithm. This uses the BKM algorithm in L-mode. \param m mantissa in [1,2) as Q1.30 \param n number of iterations (at most 32) \return log2(\a m) as Q0.31
| 1529 | /// \param n number of iterations (at most 32) |
| 1530 | /// \return log2(\a m) as Q0.31 |
| 1531 | inline uint32 log2(uint32 m, unsigned int n = 32) |
| 1532 | { |
| 1533 | static const uint32 logs[] = { |
| 1534 | 0x80000000, 0x4AE00D1D, 0x2934F098, 0x15C01A3A, 0x0B31FB7D, 0x05AEB4DD, 0x02DCF2D1, 0x016FE50B, |
| 1535 | 0x00B84E23, 0x005C3E10, 0x002E24CA, 0x001713D6, 0x000B8A47, 0x0005C53B, 0x0002E2A3, 0x00017153, |
| 1536 | 0x0000B8AA, 0x00005C55, 0x00002E2B, 0x00001715, 0x00000B8B, 0x000005C5, 0x000002E3, 0x00000171, |
| 1537 | 0x000000B9, 0x0000005C, 0x0000002E, 0x00000017, 0x0000000C, 0x00000006, 0x00000003, 0x00000001 }; |
| 1538 | if(m == 0x40000000) |
| 1539 | return 0; |
| 1540 | uint32 mx = 0x40000000, my = 0; |
| 1541 | for(unsigned int i=1; i<n; ++i) |
| 1542 | { |
| 1543 | uint32 mz = mx + (mx>>i); |
| 1544 | if(mz <= m) |
| 1545 | { |
| 1546 | mx = mz; |
| 1547 | my += logs[i]; |
| 1548 | } |
| 1549 | } |
| 1550 | return my; |
| 1551 | } |
| 1552 | |
| 1553 | /// Fixed point sine and cosine. |
| 1554 | /// This uses the CORDIC algorithm in rotation mode. |
no test coverage detected