mirror of
https://github.com/golang/go
synced 2024-11-18 19:04:40 -07:00
go.tools/go/types: extra tests for float conversions
R=adonovan CC=golang-dev https://golang.org/cl/13393046
This commit is contained in:
parent
b591789053
commit
67c866ec74
@ -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)
|
||||
}
|
||||
|
||||
|
12
go/types/testdata/const1.src
vendored
12
go/types/testdata/const1.src
vendored
@ -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 (
|
||||
|
Loading…
Reference in New Issue
Block a user