mirror of
https://github.com/golang/go
synced 2024-10-04 00:21:20 -06:00
cmd/compile: fix typo in floating point rule
Change-Id: Idfb64fcb26f48d5b70bab872f9a3d96a036be681 Reviewed-on: https://go-review.googlesource.com/63950 Run-TryBot: Todd Neal <todd@tneal.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
parent
5a986eca86
commit
af86083812
@ -197,6 +197,16 @@ func cvt12(a float32) uint {
|
|||||||
return uint(a)
|
return uint(a)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func f2i64p(v float64) *int64 {
|
||||||
|
return ip64(int64(v / 0.1))
|
||||||
|
}
|
||||||
|
|
||||||
|
//go:noinline
|
||||||
|
func ip64(v int64) *int64 {
|
||||||
|
return &v
|
||||||
|
}
|
||||||
|
|
||||||
func TestFloatConvert(t *testing.T) {
|
func TestFloatConvert(t *testing.T) {
|
||||||
if got := cvt1(3.5); got != 3 {
|
if got := cvt1(3.5); got != 3 {
|
||||||
t.Errorf("cvt1 got %d, wanted 3", got)
|
t.Errorf("cvt1 got %d, wanted 3", got)
|
||||||
@ -234,6 +244,9 @@ func TestFloatConvert(t *testing.T) {
|
|||||||
if got := cvt12(3.5); got != 3 {
|
if got := cvt12(3.5); got != 3 {
|
||||||
t.Errorf("cvt12 got %d, wanted 3", got)
|
t.Errorf("cvt12 got %d, wanted 3", got)
|
||||||
}
|
}
|
||||||
|
if got := *f2i64p(10); got != 100 {
|
||||||
|
t.Errorf("f2i64p got %d, wanted 100", got)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var sinkFloat float64
|
var sinkFloat float64
|
||||||
|
@ -53,7 +53,7 @@
|
|||||||
(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(i2f(c)))])
|
(Cvt32Fto32 (Const32F [c])) -> (Const32 [int64(int32(i2f(c)))])
|
||||||
(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(i2f(c))])
|
(Cvt32Fto64 (Const32F [c])) -> (Const64 [int64(i2f(c))])
|
||||||
(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(i2f(c)))])
|
(Cvt64Fto32 (Const64F [c])) -> (Const32 [int64(int32(i2f(c)))])
|
||||||
(Cvt64Fto64 (Const64F [c])) -> (Const32 [int64(i2f(c))])
|
(Cvt64Fto64 (Const64F [c])) -> (Const64 [int64(i2f(c))])
|
||||||
(Round32F x:(Const32F)) -> x
|
(Round32F x:(Const32F)) -> x
|
||||||
(Round64F x:(Const64F)) -> x
|
(Round64F x:(Const64F)) -> x
|
||||||
|
|
||||||
|
@ -7194,14 +7194,14 @@ func rewriteValuegeneric_OpCvt64Fto32F_0(v *Value) bool {
|
|||||||
func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool {
|
func rewriteValuegeneric_OpCvt64Fto64_0(v *Value) bool {
|
||||||
// match: (Cvt64Fto64 (Const64F [c]))
|
// match: (Cvt64Fto64 (Const64F [c]))
|
||||||
// cond:
|
// cond:
|
||||||
// result: (Const32 [int64(i2f(c))])
|
// result: (Const64 [int64(i2f(c))])
|
||||||
for {
|
for {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
if v_0.Op != OpConst64F {
|
if v_0.Op != OpConst64F {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
c := v_0.AuxInt
|
c := v_0.AuxInt
|
||||||
v.reset(OpConst32)
|
v.reset(OpConst64)
|
||||||
v.AuxInt = int64(i2f(c))
|
v.AuxInt = int64(i2f(c))
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user