| 1748 | /// \param to direction to enumerate into |
| 1749 | /// \return next representable number |
| 1750 | MEGDNN_HOST MEGDNN_DEVICE static half nextafter(half from, half to) |
| 1751 | { |
| 1752 | uint16 fabs = from.data_ & 0x7FFF, tabs = to.data_ & 0x7FFF; |
| 1753 | if(fabs > 0x7C00) |
| 1754 | return from; |
| 1755 | if(tabs > 0x7C00 || from.data_ == to.data_ || !(fabs|tabs)) |
| 1756 | return to; |
| 1757 | if(!fabs) |
| 1758 | return half(binary_t(), (to.data_&0x8000)+1); |
| 1759 | bool lt = (signbit(from) ? (static_cast<int17>(0x8000)-from.data_) : static_cast<int17>(from.data_)) < |
| 1760 | (signbit(to) ? (static_cast<int17>(0x8000)-to.data_) : static_cast<int17>(to.data_)); |
| 1761 | return half(binary_t(), from.data_+(((from.data_>>15)^static_cast<uint16>(lt))<<1)-1); |
| 1762 | } |
| 1763 | |
| 1764 | /// Sign implementation |
| 1765 | /// \param x first operand |