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

Incorrect conversion of integer to float in output #1379

Closed
notJoon opened this issue Nov 17, 2023 · 2 comments
Closed

Incorrect conversion of integer to float in output #1379

notJoon opened this issue Nov 17, 2023 · 2 comments

Comments

@notJoon
Copy link
Member

notJoon commented Nov 17, 2023

Description

package main

func main() {
	var a int = 42
	println(float32(a))
}

// Expected:
// +4.200000e+001

// Output:
// 42

When running this code, the output is 42, not +4.200000e+001 as expected when an integer is converted to a float32. This seems to be a bug in the handling of FloatKind value conversion.

@thehowl
Copy link
Member

thehowl commented Nov 17, 2023

The numbers are actually the same. The first is 4.2 * 10, which is 42.

To me it seems more likely that we are printing things in this case more readable than go :)

Are you comparing with Go's println?

@thehowl
Copy link
Member

thehowl commented Nov 24, 2023

I'm closing this as "not a bug" for now.

As mentioned in #1377, I don't think striving for compatibility with Go's println is a useful endeavour, as the documentation for Go's println specifically says that it is implementation-specific.

If you can think of a good argument of why this should be the case -- or anyone reading this agrees that we should try to have println/print work in the same way as Go's format and can make a good argument for it, please reopen (or ask to reopen) this issue and make your case.

Personally, I think we'll obviously strive for 100% compatibility when we have the language-defined fmt.Println, but println seems like a non-goal. :)

@thehowl thehowl closed this as not planned Won't fix, can't repro, duplicate, stale Nov 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Development

No branches or pull requests

2 participants