Skip to content

Commit b1115c2

Browse files
author
snopan
committed
Added comment
1 parent a6f506c commit b1115c2

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

assert/assertions.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,11 @@ func ObjectsAreEqualValues(expected, actual interface{}) bool {
198198
toValue = actualValue
199199
}
200200

201+
// If we are converting from float32 to float64, the converted value will
202+
// have trailing non zero decimals due to binary representation differences
203+
// For example: float64(float32(10.1)) = 10.100000381469727
204+
// To remove the trailing decimals we can round the 64-bit value to
205+
// expected precision of 32-bit which is 6 decimal places
201206
newValue := fromValue.Convert(toType).Interface()
202207
if fromType.Kind() == reflect.Float32 && toType.Kind() == reflect.Float64 {
203208
scale := math.Pow(10, 6)

0 commit comments

Comments
 (0)