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-
|
// the conversion succeeds but the result value is implementation-
|
||||||
// dependent."
|
// dependent."
|
||||||
//
|
//
|
||||||
// We assume that float32(f) returns an Inf if f cannot be represented
|
// We assume that float32(f) returns an Inf if f is too large for
|
||||||
// as a float32, or if f is an Inf.
|
// 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)
|
return !math.IsInf(float64(float32(f)), 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
// Use of this source code is governed by a BSD-style
|
// Use of this source code is governed by a BSD-style
|
||||||
// license that can be found in the LICENSE file.
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
// implicit constant conversions
|
// constant conversions
|
||||||
|
|
||||||
package const1
|
package const1
|
||||||
|
|
||||||
|
|
@ -248,6 +248,11 @@ const (
|
||||||
_ = float32(-maxFloat32)
|
_ = float32(-maxFloat32)
|
||||||
_ = float32(maxFloat32)
|
_ = float32(maxFloat32)
|
||||||
_ = float32(maxFloat32 /* ERROR "cannot convert" */ + delta32)
|
_ = 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)
|
const delta64 = maxFloat64/(1 << 52)
|
||||||
|
|
@ -262,6 +267,11 @@ const (
|
||||||
_ = float64(-maxFloat64)
|
_ = float64(-maxFloat64)
|
||||||
_ = float64(maxFloat64)
|
_ = float64(maxFloat64)
|
||||||
_ = float64(maxFloat64 /* ERROR "cannot convert" */ + delta64)
|
_ = 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 (
|
const (
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue