mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: change Mp{int,flt} functions into methods
Also give them more idiomatic Go names. Adding godocs is outside the scope of this CL. (Besides, the method names almost all directly parallel an underlying math/big.Int or math/big.Float method.) CL prepared mechanically with sed (for rewriting mpint.go/mpfloat.go) and gofmt (for rewriting call sites). Passes toolstash -cmp. Change-Id: Id76f4aee476ba740f48db33162463e7978c2083d Reviewed-on: https://go-review.googlesource.com/20909 Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
This commit is contained in:
parent
5fb6aa3e09
commit
d3253876f2
20 changed files with 315 additions and 315 deletions
|
|
@ -37,7 +37,7 @@ func newMpflt() *Mpflt {
|
|||
return &a
|
||||
}
|
||||
|
||||
func Mpmovefixflt(a *Mpflt, b *Mpint) {
|
||||
func (a *Mpflt) SetInt(b *Mpint) {
|
||||
if b.Ovf {
|
||||
// sign doesn't really matter but copy anyway
|
||||
a.Val.SetInf(b.Val.Sign() < 0)
|
||||
|
|
@ -46,11 +46,11 @@ func Mpmovefixflt(a *Mpflt, b *Mpint) {
|
|||
a.Val.SetInt(&b.Val)
|
||||
}
|
||||
|
||||
func mpmovefltflt(a *Mpflt, b *Mpflt) {
|
||||
func (a *Mpflt) Set(b *Mpflt) {
|
||||
a.Val.Set(&b.Val)
|
||||
}
|
||||
|
||||
func mpaddfltflt(a *Mpflt, b *Mpflt) {
|
||||
func (a *Mpflt) Add(b *Mpflt) {
|
||||
if Mpdebug {
|
||||
fmt.Printf("\n%v + %v", a, b)
|
||||
}
|
||||
|
|
@ -62,14 +62,14 @@ func mpaddfltflt(a *Mpflt, b *Mpflt) {
|
|||
}
|
||||
}
|
||||
|
||||
func mpaddcflt(a *Mpflt, c float64) {
|
||||
func (a *Mpflt) AddFloat64(c float64) {
|
||||
var b Mpflt
|
||||
|
||||
Mpmovecflt(&b, c)
|
||||
mpaddfltflt(a, &b)
|
||||
b.SetFloat64(c)
|
||||
a.Add(&b)
|
||||
}
|
||||
|
||||
func mpsubfltflt(a *Mpflt, b *Mpflt) {
|
||||
func (a *Mpflt) Sub(b *Mpflt) {
|
||||
if Mpdebug {
|
||||
fmt.Printf("\n%v - %v", a, b)
|
||||
}
|
||||
|
|
@ -81,7 +81,7 @@ func mpsubfltflt(a *Mpflt, b *Mpflt) {
|
|||
}
|
||||
}
|
||||
|
||||
func mpmulfltflt(a *Mpflt, b *Mpflt) {
|
||||
func (a *Mpflt) Mul(b *Mpflt) {
|
||||
if Mpdebug {
|
||||
fmt.Printf("%v\n * %v\n", a, b)
|
||||
}
|
||||
|
|
@ -93,14 +93,14 @@ func mpmulfltflt(a *Mpflt, b *Mpflt) {
|
|||
}
|
||||
}
|
||||
|
||||
func mpmulcflt(a *Mpflt, c float64) {
|
||||
func (a *Mpflt) MulFloat64(c float64) {
|
||||
var b Mpflt
|
||||
|
||||
Mpmovecflt(&b, c)
|
||||
mpmulfltflt(a, &b)
|
||||
b.SetFloat64(c)
|
||||
a.Mul(&b)
|
||||
}
|
||||
|
||||
func mpdivfltflt(a *Mpflt, b *Mpflt) {
|
||||
func (a *Mpflt) Quo(b *Mpflt) {
|
||||
if Mpdebug {
|
||||
fmt.Printf("%v\n / %v\n", a, b)
|
||||
}
|
||||
|
|
@ -112,18 +112,18 @@ func mpdivfltflt(a *Mpflt, b *Mpflt) {
|
|||
}
|
||||
}
|
||||
|
||||
func mpcmpfltflt(a *Mpflt, b *Mpflt) int {
|
||||
func (a *Mpflt) Cmp(b *Mpflt) int {
|
||||
return a.Val.Cmp(&b.Val)
|
||||
}
|
||||
|
||||
func mpcmpfltc(b *Mpflt, c float64) int {
|
||||
func (b *Mpflt) CmpFloat64(c float64) int {
|
||||
var a Mpflt
|
||||
|
||||
Mpmovecflt(&a, c)
|
||||
return mpcmpfltflt(b, &a)
|
||||
a.SetFloat64(c)
|
||||
return b.Cmp(&a)
|
||||
}
|
||||
|
||||
func mpgetflt(a *Mpflt) float64 {
|
||||
func (a *Mpflt) Float64() float64 {
|
||||
x, _ := a.Val.Float64()
|
||||
|
||||
// check for overflow
|
||||
|
|
@ -134,7 +134,7 @@ func mpgetflt(a *Mpflt) float64 {
|
|||
return x + 0 // avoid -0 (should not be needed, but be conservative)
|
||||
}
|
||||
|
||||
func mpgetflt32(a *Mpflt) float64 {
|
||||
func (a *Mpflt) Float32() float64 {
|
||||
x32, _ := a.Val.Float32()
|
||||
x := float64(x32)
|
||||
|
||||
|
|
@ -146,7 +146,7 @@ func mpgetflt32(a *Mpflt) float64 {
|
|||
return x + 0 // avoid -0 (should not be needed, but be conservative)
|
||||
}
|
||||
|
||||
func Mpmovecflt(a *Mpflt, c float64) {
|
||||
func (a *Mpflt) SetFloat64(c float64) {
|
||||
if Mpdebug {
|
||||
fmt.Printf("\nconst %g", c)
|
||||
}
|
||||
|
|
@ -162,7 +162,7 @@ func Mpmovecflt(a *Mpflt, c float64) {
|
|||
}
|
||||
}
|
||||
|
||||
func mpnegflt(a *Mpflt) {
|
||||
func (a *Mpflt) Neg() {
|
||||
// avoid -0
|
||||
if a.Val.Sign() != 0 {
|
||||
a.Val.Neg(&a.Val)
|
||||
|
|
@ -173,7 +173,7 @@ func mpnegflt(a *Mpflt) {
|
|||
// floating point input
|
||||
// required syntax is [+-]d*[.]d*[e[+-]d*] or [+-]0xH*[e[+-]d*]
|
||||
//
|
||||
func mpatoflt(a *Mpflt, as string) {
|
||||
func (a *Mpflt) SetString(as string) {
|
||||
for len(as) > 0 && (as[0] == ' ' || as[0] == '\t') {
|
||||
as = as[1:]
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue