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

math: Type Conversion of Inf(1) to int produces a negative integer instead of a positive one #44225

Closed
BozeBro opened this issue Feb 11, 2021 · 1 comment

Comments

@BozeBro
Copy link

BozeBro commented Feb 11, 2021

package main

import (
	"fmt"
	"math"
)

func main() {
	fmt.Println("Hello, playground")
	m := int(math.Inf(1))
	fmt.Println(m)
}

go playground

What did you expect to see?

I expected to see positive infinity representation or 9223372036854775807

What did you see instead?

-9223372036854775807

@randall77
Copy link
Contributor

This is implementation-dependent behavior, and not a bug.

The spec says:

In all non-constant conversions involving floating-point or complex values, if the result type cannot represent the value the conversion succeeds but the result value is implementation-dependent.

Unfortunately +Inf is not representable as an int.

@golang golang locked and limited conversation to collaborators Feb 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants