mirror of
				https://github.com/ciphervance/supercell-wx.git
				synced 2025-10-31 18:10:05 +00:00 
			
		
		
		
	Fix 16-bit floating point conversions
This commit is contained in:
		
							parent
							
								
									b0ebc8eab6
								
							
						
					
					
						commit
						6254b0a84e
					
				
					 2 changed files with 21 additions and 4 deletions
				
			
		|  | @ -7,6 +7,11 @@ namespace scwx | |||
| namespace util | ||||
| { | ||||
| 
 | ||||
| class Float16Test : | ||||
|     public testing ::TestWithParam<std ::pair<std::uint16_t, float>> | ||||
| { | ||||
| }; | ||||
| 
 | ||||
| TEST(FloatTest, Decode32Positive1) | ||||
| { | ||||
|    uint16_t msw = 0x3f80; | ||||
|  | @ -37,14 +42,26 @@ TEST(FloatTest, Decode32Positive12345678) | |||
|    EXPECT_FLOAT_EQ(x, 12345678.0f); | ||||
| } | ||||
| 
 | ||||
| TEST(FloatTest, Decode16h0x5bb4) | ||||
| TEST_P(Float16Test, DecodeFloat16) | ||||
| { | ||||
|    uint16_t hex = 0x5bb4; | ||||
|    auto param = GetParam(); | ||||
| 
 | ||||
|    std::uint16_t hex = param.first; | ||||
| 
 | ||||
|    float x = DecodeFloat16(hex); | ||||
| 
 | ||||
|    EXPECT_FLOAT_EQ(x, 123.25f); | ||||
|    EXPECT_FLOAT_EQ(x, param.second); | ||||
| } | ||||
| 
 | ||||
| INSTANTIATE_TEST_SUITE_P( | ||||
|    FloatTest, | ||||
|    Float16Test, | ||||
|    testing::Values(std::pair<std::uint16_t, float> {0x4400, 2.0f}, | ||||
|                    std::pair<std::uint16_t, float> {0x59ab, 90.6875f}, | ||||
|                    std::pair<std::uint16_t, float> {0x593e, 83.875f}, | ||||
|                    std::pair<std::uint16_t, float> {0x54dc, 38.875f}, | ||||
|                    std::pair<std::uint16_t, float> {0xc82a, -4.1640625f}, | ||||
|                    std::pair<std::uint16_t, float> {0x5bb4, 123.25f})); | ||||
| 
 | ||||
| } // namespace util
 | ||||
| } // namespace scwx
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Dan Paulat
						Dan Paulat