Skip to content

x/exp/stats: Quantiles should allow different types for values and quantiles #76231

@seankhliao

Description

@seankhliao

Go version

go version go1.26-devel_7995751d3a 2025-11-07 14:16:34 -0800 linux/amd64

Output of go env in your module/workspace:

AR='ar'
CC='gcc'
CGO_CFLAGS='-O2 -g'
CGO_CPPFLAGS=''
CGO_CXXFLAGS='-O2 -g'
CGO_ENABLED='0'
CGO_FFLAGS='-O2 -g'
CGO_LDFLAGS='-O2 -g'
CXX='g++'
GCCGO='gccgo'
GO111MODULE=''
GOAMD64='v3'
GOARCH='amd64'
GOAUTH='netrc'
GOBIN=''
GOCACHE='/home/user/.cache/go-build'
GOCACHEPROG=''
GODEBUG='netdns=cgo'
GOENV='/home/user/.config/go/env'
GOEXE=''
GOEXPERIMENT='jsonv2'
GOFIPS140='off'
GOFLAGS='-trimpath "-ldflags=-s -w" -vet=all'
GOGCCFLAGS='-fPIC -m64 -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build3426502725=/tmp/go-build -gno-record-gcc-switches'
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMOD='/home/user/tmp/testrepo1284/go.mod'
GOMODCACHE='/home/user/.data/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/user/.data/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/user/sdk/gotip'
GOSUMDB='sum.golang.org'
GOTELEMETRY='on'
GOTELEMETRYDIR='/home/user/.config/go/telemetry'
GOTMPDIR=''
GOTOOLCHAIN='path'
GOTOOLDIR='/home/user/sdk/gotip/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.26-devel_7995751d3a 2025-11-07 14:16:34 -0800'
GOWORK=''
PKG_CONFIG='pkg-config'

What did you do?

https://go.dev/play/p/LGyC3QbvuBd

package main

import (
	"fmt"

	"golang.org/x/exp/stats"
)

type myfloat float64

func main() {
	data := []myfloat{0.1, 0.2, 0.3, 0.4}
	quantiles := []float64{0.5, 0.99}
	fmt.Println(stats.Quantiles(data, quantiles...))
}

What did you see happen?

./prog.go:14:36: in call to stats.Quantiles, type []float64 of quantiles does not match inferred type []myfloat for []F

What did you expect to see?

No type error.


#69264 added a new package for stats
The Quantiles func has the signature https://pkg.go.dev/golang.org/x/exp/stats#Quantiles

func Quantiles[F ~float64](values []F, quantiles ...F) []F

I think it should use separate types for values and quantiles:

func Quantiles[F, Q ~float64](values []F, quantiles ...Q) []F

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a tool

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions