Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/compile: miscompilation of float64 comparison and bool comparison #34587

Closed
johnfercher opened this issue Sep 28, 2019 · 4 comments
Closed
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@johnfercher
Copy link

What version of Go are you using (go version)?

$ go version
go version go1.12.4 darwin/amd64

Does this issue reproduce with the latest release?

No.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/jfercher/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jfercher/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.4/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.4/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7p/3q7bnlnd3h9fk22hlpgngz0r0000gq/T/go-build807819520=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

totalOffsetY := self.offsetY+height+self.footerHeight
maxOffsetPage := pageHeight-bottom-top
greaterThan := totalOffsetY > maxOffsetPage

// At this point totalOffsetY is float64{7}
// maxOffsetPage is float64{80}
// and greaterThan is bool{false}.
if greaterThan == true {
	// ..
}

The greaterThan comparison is returning true.

What did you expect to see?

false must be false

What did you see instead?

false is true

@agnivade
Copy link
Contributor

Please provide a playground link which shows this.

@dsnet dsnet added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Sep 28, 2019
@mdempsky mdempsky changed the title If, always being true after float64 comparison cmd/compile: miscompilation of float64 comparison and bool comparison Oct 3, 2019
@mdempsky
Copy link
Member

mdempsky commented Oct 3, 2019

A playground link is ideal, but any way to easily reproduce this would be a good start.

@odeke-em
Copy link
Member

@johnfercher please use/modify this seed program that I derived from your report, to perhaps provide a repro for the problem otherwise this issue isn't actionable

package main

import "fmt"

type rect struct {
	offsetY      float64
	footerHeight float64
}

func main() {
	self := &rect{
		offsetY:      5,
		footerHeight: 1,
	}
	do(self)
}

func do(self *rect) {
	height := float64(1)
	pageHeight := float64(100)
	bottom := float64(10)
	top := float64(10)
	totalOffsetY := self.offsetY + height + self.footerHeight
	maxOffsetPage := pageHeight - bottom - top
	greaterThan := totalOffsetY > maxOffsetPage

	// At this point totalOffsetY is float64{7}
	// maxOffsetPage is float64{80}
	// and greaterThan is bool{false}.
	fmt.Printf("totalOffsetY: %.2f maxOffsetPage: %.2f\n", totalOffsetY, maxOffsetPage)
	if greaterThan == true {
		panic("greaterThan is supposed to be false")
	}
}

Thank you.

@gopherbot
Copy link

Timed out in state WaitingForInfo. Closing.

(I am just a bot, though. Please speak up if this is a mistake or you have the requested information.)

@golang golang locked and limited conversation to collaborators Oct 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

No branches or pull requests

6 participants