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

Function angle_arg

include/half.hpp:1604–1622  ·  view source on GitHub ↗

Reduce argument for trigonometric functions. \param abs half-precision floating-point value \param k value to take quarter period \return \a abs reduced to [-pi/4,pi/4] as Q0.30

Source from the content-addressed store, hash-verified

1602 /// \param k value to take quarter period
1603 /// \return \a abs reduced to [-pi/4,pi/4] as Q0.30
1604 inline uint32 angle_arg(unsigned int abs, int &k)
1605 {
1606 uint32 m = (abs&0x3FF) | ((abs>0x3FF)<<10);
1607 int exp = (abs>>10) + (abs<=0x3FF) - 15;
1608 if(abs < 0x3A48)
1609 return k = 0, m << (exp+20);
1610 #if HALF_ENABLE_CPP11_LONG_LONG
1611 unsigned long long y = m * 0xA2F9836E4E442, mask = (1ULL<<(62-exp)) - 1, yi = (y+(mask>>1)) & ~mask, f = y - yi;
1612 uint32 sign = -static_cast<uint32>(f>>63);
1613 k = static_cast<int>(yi>>(62-exp));
1614 return (multiply64(static_cast<uint32>((sign ? -f : f)>>(31-exp)), 0xC90FDAA2)^sign) - sign;
1615 #else
1616 uint32 yh = m*0xA2F98 + mulhi<std::round_toward_zero>(m, 0x36E4E442), yl = (m*0x36E4E442) & 0xFFFFFFFF;
1617 uint32 mask = (static_cast<uint32>(1)<<(30-exp)) - 1, yi = (yh+(mask>>1)) & ~mask, sign = -static_cast<uint32>(yi>yh);
1618 k = static_cast<int>(yi>>(30-exp));
1619 uint32 fh = (yh^sign) + (yi^~sign) - ~sign, fl = (yl^sign) - sign;
1620 return (multiply64((exp>-1) ? (((fh<<(1+exp))&0xFFFFFFFF)|((fl&0xFFFFFFFF)>>(31-exp))) : fh, 0xC90FDAA2)^sign) - sign;
1621 #endif
1622 }
1623
1624 /// Get arguments for atan2 function.
1625 /// \param abs half-precision floating-point value

Callers 4

sincosFunction · 0.85
sinFunction · 0.85
cosFunction · 0.85
tanFunction · 0.85

Calls 1

multiply64Function · 0.85

Tested by

no test coverage detected