Multiplication. This operation is exact to rounding for all rounding modes. \param x left operand \param y right operand \return product of half expressions \exception FE_INVALID if multiplying 0 with infinity or if \a x or \a y is signaling NaN \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding
| 2615 | /// \exception FE_INVALID if multiplying 0 with infinity or if \a x or \a y is signaling NaN |
| 2616 | /// \exception FE_OVERFLOW, ...UNDERFLOW, ...INEXACT according to rounding |
| 2617 | inline half operator*(half x, half y) |
| 2618 | { |
| 2619 | #ifdef HALF_ARITHMETIC_TYPE |
| 2620 | return half(detail::binary, detail::float2half<half::round_style>(detail::half2float<detail::internal_t>(x.data_)*detail::half2float<detail::internal_t>(y.data_))); |
| 2621 | #else |
| 2622 | int absx = x.data_ & 0x7FFF, absy = y.data_ & 0x7FFF, exp = -16; |
| 2623 | unsigned int sign = (x.data_^y.data_) & 0x8000; |
| 2624 | if(absx >= 0x7C00 || absy >= 0x7C00) |
| 2625 | return half(detail::binary, (absx>0x7C00 || absy>0x7C00) ? detail::signal(x.data_, y.data_) : |
| 2626 | ((absx==0x7C00 && !absy)||(absy==0x7C00 && !absx)) ? detail::invalid() : (sign|0x7C00)); |
| 2627 | if(!absx || !absy) |
| 2628 | return half(detail::binary, sign); |
| 2629 | for(; absx<0x400; absx<<=1,--exp) ; |
| 2630 | for(; absy<0x400; absy<<=1,--exp) ; |
| 2631 | detail::uint32 m = static_cast<detail::uint32>((absx&0x3FF)|0x400) * static_cast<detail::uint32>((absy&0x3FF)|0x400); |
| 2632 | int i = m >> 21, s = m & i; |
| 2633 | exp += (absx>>10) + (absy>>10) + i; |
| 2634 | if(exp > 29) |
| 2635 | return half(detail::binary, detail::overflow<half::round_style>(sign)); |
| 2636 | else if(exp < -11) |
| 2637 | return half(detail::binary, detail::underflow<half::round_style>(sign)); |
| 2638 | return half(detail::binary, detail::fixed2half<half::round_style,20,false,false,false>(m>>i, exp, sign, s)); |
| 2639 | #endif |
| 2640 | } |
| 2641 | |
| 2642 | /// Division. |
| 2643 | /// This operation is exact to rounding for all rounding modes. |