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: Float.Append and Float.Text do not set Accuracy #18650

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

math/big: Float.Append and Float.Text do not set Accuracy #18650

mpvl opened this issue Jan 13, 2017 · 3 comments

Comments

@mpvl
Copy link
Contributor

mpvl commented Jan 13, 2017

Please answer these questions before submitting your issue. Thanks!

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?

Calling Append and Text on big.Float and determine the accuracy of the result.
https://play.golang.org/p/gxa_HDy-Ul

What did you expect to see?

I expected Acc to give the accuracy of the last operation, as documented, in this case being Text or Append.

There currently seems to be no way to determine the accuracy of a printed string. If this cannot be supported, an alternative solutions would be: a) have a separate method to get the digits of a float, b) have a big.Decimal that allows to be converted to that would allow getting the information in a similar way as is possible with SetPrec and the like in big.Float.

What did you see instead?

It does not.

@ALTree
Copy link
Member

ALTree commented Jan 13, 2017

I expected Acc to give the accuracy of the last operation, as documented, in this case being Text or Append.

But Text and Append do not change the receiver... they just generate strings. Why do you expect Acc to change? Acc describes the rounding error of the last operation that sets/modifies the big.Float value. When you call f.Text('f', 0), f is untouched, and so is its f.acc field.

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

/cc @griesemer

@griesemer
Copy link
Contributor

Per https://golang.org/pkg/math/big/#Float.Acc, Acc returns the accuracy of a value produced by the most recent operation. Your computing the the accuracy of f which has not changed after creation. This is working as intended as @ALTree already pointed out.

A printed string is a string and you can do whatever you want with it. I don't know what "accuracy of a printed string" should be.

There's already a MathExp function that allows you to split out the mantissa and exponent of a *Float, and the same techniques we use for float64 values can be used to create an (big.Int)eger value from it can be used.

@golang golang locked and limited conversation to collaborators Jan 14, 2018
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

5 participants