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/big: printing float is not respecting RoundingMode #18649

Closed
mpvl opened this issue Jan 13, 2017 · 3 comments
Closed

math/big: printing float is not respecting RoundingMode #18649

mpvl opened this issue Jan 13, 2017 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mpvl
Copy link
Contributor

mpvl commented Jan 13, 2017

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

go version go1.7 darwin/amd64

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go1.7"
GOTOOLDIR="/usr/local/go1.7/pkg/tool/darwin_amd64"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -gno-record-gcc-switches -fno-common"
CXX="clang++"
CGO_ENABLED="1"

What did you do?

Rounded a big.Float using formatting and using SetPrec to the same precision and using the same RoundingMode.
https://play.golang.org/p/wqWAnOzf45

What did you expect to see?

I expected formatting of numbers should also respect the rounding mode.

Not sure if this was intentional, but putting it out there.

What did you see instead?

It does not.

@ianlancetaylor ianlancetaylor added this to the Go1.9 milestone Jan 13, 2017
@griesemer
Copy link
Contributor

Note that the behavior for big.Floats is the same as for float64 with respect to printing: https://play.golang.org/p/z_Y_hIg9Cq

I'm not saying there's no issue here, but if there is, it's also in strconv. Haven't had time to investigate in more detail.

@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 13, 2017
@mpvl
Copy link
Contributor Author

mpvl commented Jan 24, 2017

Background; I'm adding this ability to x/text repo for number formatting. Right now I have the unfortunate situation that I can't rely on much of the code in core to do number formatting (or formatting in general). I can also show you what I end up with and then see how to retrofit it in core if there is a desire to not have duplicate code.

@griesemer
Copy link
Contributor

The "issue" here is that the rounding mode for formatting is always RoundToNearestEven. This matches the strconv library.

If you need to round than do it before formatting and you get the desired result: https://play.golang.org/p/iSo7VROcPj

@golang golang locked and limited conversation to collaborators Jan 25, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants