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

Function sin

include/half.hpp:3530–3553  ·  view source on GitHub ↗

Sine function. This function is exact to rounding for all rounding modes. See also:** Documentation for [std::sin](https://en.cppreference.com/w/cpp/numeric/math/sin). \param arg function argument \return sine value of \a arg \exception FE_INVALID for signaling NaN or infinity \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding

Source from the content-addressed store, hash-verified

3528 /// \exception FE_INVALID for signaling NaN or infinity
3529 /// \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding
3530 inline half sin(half arg)
3531 {
3532 #ifdef HALF_ARITHMETIC_TYPE
3533 return half(detail::binary, detail::float2half<half::round_style>(std::sin(detail::half2float<detail::internal_t>(arg.data_))));
3534 #else
3535 int abs = arg.data_ & 0x7FFF, k;
3536 if(!abs)
3537 return arg;
3538 if(abs >= 0x7C00)
3539 return half(detail::binary, (abs==0x7C00) ? detail::invalid() : detail::signal(arg.data_));
3540 if(abs < 0x2900)
3541 return half(detail::binary, detail::rounded<half::round_style,true>(arg.data_-1, 1, 1));
3542 if(half::round_style != std::round_to_nearest)
3543 switch(abs)
3544 {
3545 case 0x48B7: return half(detail::binary, detail::rounded<half::round_style,true>((~arg.data_&0x8000)|0x1D07, 1, 1));
3546 case 0x6A64: return half(detail::binary, detail::rounded<half::round_style,true>((~arg.data_&0x8000)|0x3BFE, 1, 1));
3547 case 0x6D8C: return half(detail::binary, detail::rounded<half::round_style,true>((arg.data_&0x8000)|0x0FE6, 1, 1));
3548 }
3549 std::pair<detail::uint32,detail::uint32> sc = detail::sincos(detail::angle_arg(abs, k), 28);
3550 detail::uint32 sign = -static_cast<detail::uint32>(((k>>1)&1)^(arg.data_>>15));
3551 return half(detail::binary, detail::fixed2half<half::round_style,30,true,true,true>((((k&1) ? sc.second : sc.first)^sign) - sign));
3552 #endif
3553 }
3554
3555 /// Cosine function.
3556 /// This function is exact to rounding for all rounding modes.

Callers 1

sincosFunction · 0.70

Calls 5

halfClass · 0.85
invalidFunction · 0.85
signalFunction · 0.85
sincosFunction · 0.85
angle_argFunction · 0.85

Tested by

no test coverage detected