diff --git a/go/types/expr.go b/go/types/expr.go index c4478585..e71b2d96 100644 --- a/go/types/expr.go +++ b/go/types/expr.go @@ -163,8 +163,9 @@ func fitsFloat32(x exact.Value) bool { // the conversion succeeds but the result value is implementation- // dependent." // - // We assume that float32(f) returns an Inf if f cannot be represented - // as a float32, or if f is an Inf. + // We assume that float32(f) returns an Inf if f is too large for + // a float32, or if f is an Inf; and that it returns 0 for values + // with too small a magnitude. return !math.IsInf(float64(float32(f)), 0) } diff --git a/go/types/testdata/const1.src b/go/types/testdata/const1.src index a600fdc6..df4d5229 100644 --- a/go/types/testdata/const1.src +++ b/go/types/testdata/const1.src @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. -// implicit constant conversions +// constant conversions package const1 @@ -248,6 +248,11 @@ const ( _ = float32(-maxFloat32) _ = float32(maxFloat32) _ = float32(maxFloat32 /* ERROR "cannot convert" */ + delta32) + + _ = assert(float32(smallestFloat32) == smallestFloat32) + _ = assert(float32(smallestFloat32/2) == 0) + _ = assert(float32(smallestFloat64) == 0) + _ = assert(float32(smallestFloat64/2) == 0) ) const delta64 = maxFloat64/(1 << 52) @@ -262,6 +267,11 @@ const ( _ = float64(-maxFloat64) _ = float64(maxFloat64) _ = float64(maxFloat64 /* ERROR "cannot convert" */ + delta64) + + _ = assert(float64(smallestFloat32) == smallestFloat32) + _ = assert(float64(smallestFloat32/2) == smallestFloat32/2) + _ = assert(float64(smallestFloat64) == smallestFloat64) + _ = assert(float64(smallestFloat64/2) == 0) ) const (