Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Pow operator produces incorrect Go translation #10

Open
@ns-cweber

Description

Python's pow operator (x**2) produces math.Pow(x, 2) in Go; however, in Go, math.Pow() only accepts floats, but in Python, ** handles ints as well as floats. This means the Python program:

x = 2
print(x**2)

Translates to

// package decl and imports elided
func main() {
	x := 2 // int
	fmt.Println(math.Pow(x, 2))
}

Which fails to compile with error: ./foo.go:10: cannot use x (type int) as type float64 in argument to math.Pow

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

        AltStyle によって変換されたページ (->オリジナル) /