MCPcopy Create free account
hub / github.com/apache/singa / log2

Function log2

include/half.hpp:1531–1551  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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.

Callers 8

areaFunction · 0.85
gammaFunction · 0.85
logFunction · 0.85
log10Function · 0.85
log1pFunction · 0.85
cbrtFunction · 0.85
powFunction · 0.85
atanhFunction · 0.85

Calls 6

halfClass · 0.85
poleFunction · 0.85
invalidFunction · 0.85
signalFunction · 0.85
sign_maskFunction · 0.85
absFunction · 0.70

Tested by

no test coverage detected