File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -154,6 +154,13 @@ TEST(FloatToHalf, RoundsDownToEvenNumber)
154154 ASSERT_EQ (get_bits (x), get_bits (" 1" " 00000" " 0000111010" ));
155155}
156156
157+ TEST (FloatToHalf, RoundsDownToEvenNumber2)
158+ {
159+ half x = create_from_bits<float >(" 1" " 01101100" " 11010100000000000000001" );
160+
161+ ASSERT_EQ (get_bits (x), get_bits (" 1" " 00000" " 0000111011" ));
162+ }
163+
157164
158165TEST (FloatToHalf, LargestNumberThatConvertsToZero)
159166{
Original file line number Diff line number Diff line change @@ -418,8 +418,9 @@ class alignas(std::uint16_t) half {
418418 // gap to fp16 denormal exponents (+1 from normal to denormal
419419 // exponent base)
420420 const auto gap_to_fp16 =
421- (conv::bias_change - ((data_ & f32_traits::exponent_mask) >>
422- conv::significand_offset) >>
421+ ((conv::bias_change -
422+ ((data_ & f32_traits::exponent_mask) >>
423+ conv::significand_offset)) >>
423424 f16_traits::significand_bits) +
424425 1 ;
425426
@@ -491,11 +492,11 @@ class alignas(std::uint16_t) half {
491492
492493 leading_zeros = f16_traits::significand_bits - index - 1 ;
493494#else
494- leading_zeros =
495- __builtin_clz ( static_cast <std:: uint32_t >(
496- f16_traits::significand_mask & data_)) -
497- f16_traits::exponent_bits - f16_traits::sign_bits -
498- 8 * ( sizeof (conv::result_bits) - sizeof (conv::source_bits));
495+ leading_zeros = __builtin_clz ( static_cast <std:: uint32_t >(
496+ f16_traits::significand_mask & data_)) -
497+ f16_traits::exponent_bits - f16_traits::sign_bits -
498+ CHAR_BIT * ( sizeof (conv::result_bits) -
499+ sizeof (conv::source_bits));
499500#endif
500501
501502 // Computes the new exponent, 0xxxxxxxx000...00
You can’t perform that action at this time.
0 commit comments