Skip to content

math/big: document that shallow copies of big.Int/Rat/Float are not supported #28423

@QuantumGhost

Description

@QuantumGhost

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

go version go1.11.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/qg/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/qg/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.11.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.11.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/02/nfvdwz45077g85khfsv07khm0000gn/T/go-build594965128=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

go playground
Run this code under 1.10 and 1.11 respectively.

package main

import (
	"fmt"
	"math/big"
)

const Int32Prime = 47

func main() {
	int32Prime := big.NewInt(Int32Prime)
	inverse := *int32Prime

	inverse.ModInverse(&inverse, big.NewInt(2))
	if int32(int32Prime.Int64()) != Int32Prime {
		fmt.Println("Changed!")
	} else {
		fmt.Println("Not Changed")
	}
}

go 1.10 prints Not Changed
go 1.11 prints Changed!

What did you expect to see?

The value of int32Prime should not be changed.

What did you see instead?

The value of int32Prime changed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions