716 using FDest = FSmall;
717 using FSource = FLarge;
718 using namespace OperatorsHelper;
727 const bool exponent_full = (exponent > delta_exponents +
FDest::template max_exponent_with_bias<T>());
728 const bool delete_mantissa = exponent_full && exponent <= FSource::template max_exponent_with_bias<T>();
731 const bool denormal = exponent <= delta_exponents;
732 const bool zero = exponent + FDest::mantissa_size_bits() <= delta_exponents;
734 const T final_exponent =
min(clamped_sub(exponent, delta_exponents),
FDest::template max_exponent_with_bias<T>() + 1);
736 const T extra_mantissa_shift = clamped_sub(delta_exponents + 1, exponent) * denormal;
737 const T total_mantissa_shift = (FSource::mantissa_size_bits() - FDest::mantissa_size_bits()) + extra_mantissa_shift;
740 const T check_for_rounding_mask =
FSource::template mantissa_mask<T>() & (~mantissa_keep_mask);
742 const T first_discarded_bit_mask = last_mantissa_bit >> 1;
745 const T extra_denormal_bit = safe_rshift(
T(denormal) << FDest::mantissa_size_bits(), extra_mantissa_shift);
747 const bool round_up = (mantissa & check_for_rounding_mask) > first_discarded_bit_mask;
748 const bool tie_break = ((mantissa & check_for_rounding_mask) == first_discarded_bit_mask);
750 const bool round_bit =
FDest::template round_results<T>(sign_bit, mantissa & last_mantissa_bit, round_up, tie_break, rt) && !(exponent_full && !delete_mantissa && !denormal);
753 T final_mantissa = (safe_rshift(mantissa, total_mantissa_shift) | extra_denormal_bit) + round_bit;
755 final_mantissa *= !delete_mantissa;
757 return sign_bit *
FDest::template sign_mask<T>() | ((final_exponent << FDest::mantissa_size_bits()) | final_mantissa) * !
zero;