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.Text panics with prec < -11 #15918

Closed
ALTree opened this issue Jun 1, 2016 · 4 comments
Closed

math/big: Float.Text panics with prec < -11 #15918

ALTree opened this issue Jun 1, 2016 · 4 comments
Milestone

Comments

@ALTree
Copy link
Member

ALTree commented Jun 1, 2016

$ gotip version
go version devel +a93a124 Tue May 31 15:33:01 2016 +0200 linux/amd64

The documentation of the (x *Float) Text(format byte, prec int) string function says

A negative precision selects the smallest number of decimal digits necessary to identify the value x uniquely.

This is true for -11 < prec < 0, but for prec < -10 the function panics instead:

package main

import (
    "fmt"
    "math/big"
)

func main() {
    z := new(big.Float).SetRat(big.NewRat(1, 3))
    fmt.Println(z.Text('f', -11))

}

playground link.

panic: runtime error: makeslice: cap out of range

goroutine 1 [running]:
panic(0x1886a0, 0x1040a138)
    /usr/local/go/src/runtime/panic.go:481 +0x700
math/big.(*Float).Text(0x10427f70, 0x10430266, 0xfffffff5, 0x0, 0x0, 0x0)
    /usr/local/go/src/math/big/ftoa.go:45 +0x60
main.main()
    /tmp/sandbox979738453/main.go:10 +0xa0
@griesemer griesemer self-assigned this Jun 1, 2016
@griesemer griesemer added this to the Go1.8 milestone Jun 1, 2016
@ALTree
Copy link
Member Author

ALTree commented Jun 1, 2016

I have a simple patch, will send for go1.8.

@griesemer
Copy link
Contributor

If it's simple enough, send it to me now, please.

@ALTree
Copy link
Member Author

ALTree commented Jun 1, 2016

@gopherbot
Copy link

CL https://golang.org/cl/23633 mentions this issue.

@golang golang locked and limited conversation to collaborators Jun 1, 2017
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