Skip to content

Pow operator produces incorrect Go translation #10

@ns-cweber

Description

@ns-cweber

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
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions